Undoped and Ga-doped ZnO films are grown on GaN templates by plasma-assisted molecular beam epitaxy for systematic investigation of the influence of native defects on their electrical properties. The distinct electrical properties of the undoped and Ga-doped ZnO films are observed after thermal treatment in a nitrogen and an oxygen ambient. It is found that the undoped ZnO films show improved characteristics when annealed in an oxygen ambient, and the Ga-doped ZnO films exhibit stable characteristics when annealed in a nitrogen ambient. The variation in electrical properties revealed by the photoluminescence measurements can be attributed to the generation and annihilation of native defects, which are dependent on the ambient of treatments. The properties of the annealed undoped ZnO films grown in an O-rich environment are affected mainly by the oxygen vacancies, antisite oxygen and oxygen interstitials, while the annealed Ga-doped ZnO films are dominated by oxygen interstitials.