I believe that this question is not about what fingering is best for a certain exact pitch; I believe the OP is confused about the difference between "D" in different octaves. Meredith's answer addresses this best. One detail that isn't addressed yet:
If you're reading traditional staff notation, then it's clear which exact pitch is intended. This note:
is D5, with a frequency of 587.33 Hz; meanwhile this one :
is D4, 293.66 Hz.
But if you're reading from a page that just contains the letter D
, then you don't have this information. This often comes up if you're reading from chord notation. For example, you could see this:
These "G, C, G" letters aren't really intended for a melodic instrument. They're intended for a chordal instrument like a guitar or piano, and when they see "G" they'll actually play a combination of G, B, and D; and there's no saying which octave each note will be in; they get to pick. If you're reading from a chord chart like this on a melodic instrument, you can pick as well. Later you can be more adventurous, but playing the letter that's printed is not a bad way to start.
But sometimes, especially for beginners, letter notation is used for a melody:

In this example, it does matter which octave you play each note in. As you go from C to G at the beginning, the tune goes up, not down to a lower G. Here's the important part: this notation doesn't tell you that. The only way you're supposed to know is either that you already know the tune by ear, or perhaps you're playing on an instrument that can only play very few notes (like an ocarina), or you have only been taught a small subset of notes so far. If you're not in this situation, then you can either choose which octave you want—or better yet, throw that notation away and find something more clear (like learning staff notation). If you change the octave of pitches in a tune willy-nilly, it's no longer the same tune.
Finally, there is a notation that uses letter names and specifies which octave to play; that's "ABC notation". In this case, the octave is indicated by Helholtz notation, using upper-case or lower-case letters and tick marks.