For key signatures with sharps, the key signature is the note name half step above the last sharp. This is the key of G because F# is the last sharp in the key signature. G is half step above F#. This is the key of E because E is half step above D#, which is the last sharp in the key signature.