A p–n junction is formed at the boundary between a p-type and n-type semiconductor created in a single crystal of semiconductor by doping, for example by ion implantation, diffusion of dopants, or by epitaxy (growing a layer of crystal doped with one type of dopant on top of a layer of crystal doped with another type of dopant). If two separate pieces of material were used, this would introduce a grain boundary between the semiconductors that severely inhibits its utility by scattering the electrons and holes