The melody isn't in a key
In this particular case, it's a bit tricky to spot the key, because, strictly speaking, the song isn't "in a key".
The melody is built around a pentatonic scale: D - E - F# - A - B. That makes it sound major-ish, but it lacks a key element — the "leading tone", C#. The movement between the seventh and eighth (first) degrees of a major scale are one of the principal characteristics of major (and minor, when the seventh degree is raised to form a leading tone). Nevertheless, it's conventional to use the D major key signature for a D pentatonic melody. One of the functions of the harmonization is to add the leading tone via the A chords, making the song D major.
See also: Wikipedia
Alfred Zoller chose the pentatonic scale as the melodic material. (translated from German via Google).
How to hear D as the pitch center
For this melody, one's ear needs to notice how the tue revolves around D in the first, second, and fourth lines. Each begins on D and returns to D, importantly at the beginning of each measure, the most metrically significant beats (i.e., most emphasized).
The case against G
To make the case against G, one notes that the melody never proceeds from F# to G, which would be a primary, characteristic element of G major.
D major with no C toneconfusing/misleading? The title alone makes one think "Well, obvs!" and the question is really "why is this piece in D?" – Grimm The Opiner Jan 08 '24 at 14:11