There are several steps to protecting your computer.
The first step is to use common sense. Don't open attachments from people you don't know, and be wary of automatic downloads you don't recognize.
Next, get anti-virus software such as AVG Free Edition or Norton Antivirus. If you are running Windows, you should also get an anti-spyware program if your anti-virus doesn't come with one.
Finally, is to protect your network. If you are on a shared connection like a wireless network or a networked DSL line, make sure that your router's firmware is up to date. Newer versions of the firmware will often protect you from hackers better than older revisions can.