when we join p type and n type semiconductors together, pn jn diode is formed. it allows current to flow in forward bias(ie when p connected to positive and n connected to negative) and stops current through it in reverse bias.so it works like a valve. this pn diode is very useful for various useful operations.
here in this diode we can control current by varying the output voltage.
now p type semiconductor is obtained by adding impurity of pentavalent atom in the pure semiconductor(say si). so there we get enough free electrons which can flow if pd is applied.
n type semiconductor we get by adding impurity of trivalent atoms in pure semiconductors. so thetre will be defficiency of electrons called holes.which move when pd is applied.