As Java is a statically typed language (meaning that variables are strongly typed and do no change type at runtime, unlike dynamically typed languages like Perl, Python, Groovy etc), it is possible to build tools that can analyze your code and look for common problems.
There are a number of these tools already out there, including FindBugs and PMD. Greg Sporar gives a quick overview of each in his blog on java.net.