1) Always be aware of your surroundings. Do not walk with your eyes on a newspaper or in a book; do not drive while distracted.
2) Walk with confidence and purpose. If you look like an easy target, you're more likely to become a target.
3) Walk with friends. Criminals are less likely to target groups than individuals.
4) Train in a martial art, or just generally stay in shape. You're less likely to be accosted if you look like you can defend yourself.
5) You could carry a weapon, but I don't recommend it; a weapon can be taken from you and used against you, plus it adds a whole new level of responsibility to your life. Not a step to be taken lightly.