For example, if I pass a random person on the sidewalk in Japan, would it be appropriate to say こんにちは? I've had people do that to me. Is it considered friendly? Polite? Rude? Does it depend on the situation? If so, when is it appropriate?
It's ok if:
- You are hiking, or climbing
- You know them or the social circle is small enough that you'll see them fairly often (like in a small village, same block, or in an apartment)
Otherwise it won't be seen as rude, but people will wonder what's going on because it's unusual, especially in big cities. They also might start to try avoid you (like say you say hello to someone on a commute, they might think "Oh well guess I take one train earlier from now on". That's only half joke.
If you obviously look you could be unfamiliar with Japanese culture they might cut you a slack. So yeah you can't do a lot of harm but it's unusual for sure.