At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
It creates a condition where current can only appreciably flow in one direction. The P side has an excess of holes. The N side has an excess of electrons. When they touch, electrons flow from the N side to the P side. The electrons on the P side combine with the holes there and create a negatively charged region near the junction. The electrons that left the N side leave behind a positively charged region. Those two regions generate an electric field that will become strong enough to prevent any more electrons or holes to cross over. After this steady state is reached, if you apply a positive voltage to the P side with respect to the N side, current will flow such that electrons are pulled out of P, through the wire and placed into the N material. This removes electrons from the - charged P region in contact with the N material, reducing the electric field there and allowing charges to cross from the N material to the P material. In other words, current can flow. If you apply a negative voltage to the P side with respect to the N side, the battery will attempt to pull electrons out of the N material and place them into the P material. This will make the -ve region in the P side more negative and the +ve region in the N material more positive. In other words, the electric field will strengthen until it can oppose the battery voltage and no current flows.
junkyard has well explained pn junction barrier. There are two more points. 1) PN junction is never made by joining one P-type semiconductor and one n-type semiconductor. These are made on same wafer of IC. 2) To explain positive ion formation in n-type side. |dw:1359867959263:dw| phosphorus, has got a free electron, that is why it the semiconductor is called n-type, because of these non-bonded free electrons. When this very electron has moved to P-type semiconductor from PN interface to p-bulk. Thus there is charge instability in Phosphorus. This makes a positive ion in n-side. Similarly for p-side consider the diagram |dw:1359868390157:dw| there is a hole, caused due to Boron doping. But semiconductor is neutral. But the extra electron from n-side can recombine with hole, and take part in bond. Thus although Silicon bonds are complete now, but Boron has got an extra electron than its protons in nucleus, Thus it turns out in positive ion.