If you look like you are aware of your surroundings and you walk with confidence there's less of a chance that you'll attract the bad people. If you look timid or afraid, you'll get jumped. Don't challenge anyone by staring at them, but don't walk looking down, either. Think of the way dogs react to each other. If one dog stares at another, they'll be a fight.
If someone says 'hello' you can say hello back. I found that if someone makes a negative comment, I can react by acting pissed off (but not confrontational). I'll say in an angry voice something to the effect of, "Don't give me any shit. I've got enough on my mind. Fuck it!" Maybe I'm a little crazy, they might think. At least, I'm unpredictable and better left alone. I think technique this works for me because it's unexpected. They don't expect this coming from a 5'2" middle-aged women.
Walk like you own the street. This is very important. I do something i call 'the New York stance'. I stand solidly, with my legs slightly apart, my shoulders back and my arms folded (or at least not hanging loosly). I keep my breath even. I survey the territory, but I don't let my eyes dart around. I pay attention not just to what I see, but to sounds and smells.
Don't show fear. When you back off from a possibly confrontational situation, don't turn your back. Face the person but hold your hands up, palms out and say, "Hey, I don't want to have any problems, OK?" Smile a friendly smile. Actually, that works well even when you're just walking, minding your own business.
I had a friend who was walking through Central Park in NYC at 2:00 am, a number of years ago. Some guy jumped out from behind a bush and waved a knife around, demanding money. My friend (who was about 5'6" and slender) laughed. "Do I look like I have any money?" My friend walked on the the robber went back behind his bush.