Ways of getting infected
People usually get infected from other infected people sexually. Other possible ways are through the blood, before or during the birth and through breast feeding.
It should be noted that HIV infection is not very much contagious. You cannot as easy get infected as with, say respiratory or intestinal infections. HIV is not transferred during usual communications with infected people. It is unlikely to be infected if you come into contact with sweat, tears, urine, saliva (unless if blood is present in it).
The best way of preventing HIV infection when having sexual intercourse is usage of condoms. Use it in all cases when you are not 100% sure that your sex partner is not infected. It is recommended to limit the number of sexual partners and do not reuse injection needles, share razors and other personal things that may come into contact with the blood.
Care should be taken to prevent a baby infection from the infected mother.