A PN junction is called a diode which is simply a voltage controlled on/off switch.
It is made by joining the P type material and N type material together.
A P type material is the instrinsic silicon (pure) doped with P type impurities, the element which has one less valence electron compared to silicon. This type is called extrinsic material
A N type material is the instrinsic silicon (pure) doped with N type impurities, the element which has one more valence electron compared to silicon.
By doping N and P type impurities, or adding these impurities, the silicon conducts better because of the addition of carriers from impurities and so N type the majority carriers are electrons and P type the majority carriers are holes (room for electrons). Both type still have some minor carrier of the other types.
Joining the N and P type material together, interesting results occurs. See the picture below:
Near the junction, the free electrons moves from N type to the holes of the P types. As the carriers are combined, the junction is now depletion of carriers thus having a potential barrier which acts like an insulation layer as the region does not have carrier to allow the moving of electrons. Therefore the region is called depletion region or space charged region. A little potential does exist in the junction and is about 0.7 volts for silicon.
In order to remove this potential barrier, a positive potential is applied on the P type material to draw the filled electrons away from the depletion region. By doing this, the free electron on the N type material will not be blocked by the junction and if the negative potential is applied, the electron will be able to move from the negative to the positive side. In other words, conventional current now can flow from P type to N type material.
However if the potential is reversed, that is, applying a negative to the P type and positive to the N type, the space charge region only increases the potential barrier further and the carriers are blocked on both side of the material.
Therefore this PN junction or diode conducts only depending on how a voltage is applied across the two terminal. Most of the time, this device is to protect the circuit polarity from the mistake made by the user. It is also used to rectify AC (alternatiing current) to DC (direct current). Some circuit such as digital circuit requires DC to operate.