There is no one thing you can do to secure your computer 100%. You have to use the "castle" approach where you apply layers of security.
1) install an antivirus program and maintain the AV with the latest scan engine and definition files.
2) keep your computer up to date on all of the latest security patches, including 3rd party apps such as Java and Adobe.
3) Keep your computers on your private network behind a firewall or NAT so that you do not allow unsolicited traffic into your network.
4) Do not open email, or click on attachments from people you dont know and for those emails of people you do know, still be careful with attachments.
5) Run a URL filtering app on your computer or on your perimieter firewall. this will prevent you from accessing sites on the internet that have been flagged as comprimised or malicious.
6) If you have a wireless network, make sure that you are using the newer authentication and encryption mechanisms.
7) Use complex passwords, never share passwords, and educate other users on your network about good security practices.
JorgeM's points are well taken. That said (and I know it isn't too feasible these days), the only 100% (more or less) sure way to avoid hacking is to stay disconnected from the Internet... :-) Firewalls, NAT's, A/V, malware scanners, rootkit scanners, and keeping a close eye on attachments you are sent are all appropriate.
Very important - be very careful what software you install on your computer. Every six months or so I have to thoroughly clean the computers used by my brother and father-in-law. They install every program and browser add-on that can be downloaded.
Disable autorun on all devices. A recent test involved dropping USB memory sticks outside a government building in the parking lot. Around 70% of the dropped sticks that were picked up by employees were inserted into their work PCs. The sticks had a harmless payload that basically sent a "hello" to a remote computer before deleting itself but it proved how vulnerable any system is to attack. Often the weak link in your computer security is you.