Depending on their language of origin, and common usage, G can have either sound. One general rule is that the G followed by an E, I, or Y is usually pronounced as a J. But there are several notable exceptions.
Examples : gem, genuine, gist, gymnast
Exceptions : gecko, get, giblets, gynecology
(For further info, see the related link)