In a p-n junction, a p-type and an n-type semiconductor are connected. The natural flow of electrons in a p-n junction is from the excess electrons in the n-type semiconductor to the empty energy levels of the p-type semiconductor.
Only when an external electric potential is connected then the electrons flow in this natural direction, and the current flow easily.
If the external electric potential is connected reverse the natural flow of electrons, no current flows through the system.
A p-n junction only transmits a current under forward bias by converting the alternating current to a direct current.
A rectifier is a device that allows only alternating current to flow in one direction. A p-n junction makes an excellent rectifier.