First I'd ask why you care if he is in your room. If it's because he doesn't know things about you, like that you are gay, that's probably causing you to be a bit more upset than you might otherwise be, and I'd ask myself if it was worth it to tell him.
Second, it might be because you don't trust him-- maybe you are afraid he's taking your stuff, spying on you, etc. If that's the case, then you might want to move.
Or hopefully it's just that he has bad manners. It might help if you explain to him why it bothers you-- such as "look, I don't want you to see me jerking off, so stay out of my room and learn to knock." Or "it startles me when you walk into my room unannounced." Then add some consequences "if you don't stop, I am moving out." If he agrees to try to stop, then I'd try it a while. If he doesn't agree that there is anything wrong with it, then you should probably move, or if you can't, get a lock.
I had a roommate once who would walk into my room at night and get in bed with me. It wouldn't have been a problem if he had wanted to sleep in the bed when I went to sleep, but it startled me when he did it in the middle of the night, and it also bothered me because it was a sign that he had some deeper issues that I couldn't deal with. He did a lot of stuff like that, and we both quickly realized we were incompatible and moved away. Hope you have better luck.