"Different ways to get your male roommate to bug off" joke
Get him laid. That's what he really needs. He will stop paying attention to you and pay attention to someone else.
Use the direct approach. When he comes in, say, "I'm doing homework now. Can I talk to you later?." If that's too polite, say "Go away now. I'm doing homework."
Use the "bad cat" approach. Purchase a high-powered squirt gun. Whenever he does something like that, say "I'm doing my homework. Anyone interrupting me will be wet." Then, blast away. He's been warned. I've discovered that this is an excellent way to keep my cat from scratching the furniture. I yelled at him and moved him until I realized that he was doing it for attention. After I squirted him three different times, he stopped permanently. Use a squirt bottle if the gun is too silly.
Buy a monster stereo and some tapes of the Sex Pistols, the Misfits, the BeeGees, and Barry Manilow. Turn it on and play it really loud when you don't want to be interrupted.
Set a small bear trap near the door. Cover it with a towel.
Not enough votes...