<p>

With a growing code base, it is good to have tools which can automatically find weaknesses in it, be it duplicate code, bad patterns, possible bugs, bad formatting, or bad design. Here are some of the tools that can analyze Java Code.

CheckStyle, FindBugs, PMD – Java Static Code Analysis

These three tools are generally the first tools suggested for Java static code analysis, as they work well together:

  • PMD – Find Bad Coding Practices
  • FindBugs – Find Bugs
  • CheckStyle – Enforce Coding Conventions and Standards

For me, FindBugs doesn’t find all that much in my code, and CheckStyle finds way too much (so custom configuration is strongly recommended).

In Netbeans, you can install all three tools by installing SQE. In Eclipse, you will have to install each one on its own. CheckStyle, PMD, and FindBugs also each have a stand-alone version, so you can run them on the command line, or integrate them with your (Ant) build process.

pro Quality Tool the most used static code analysis tools for Java
contra Quality Tool CheckStyle: no Java 8 Support (as of beginning 2015)

Recommendation:
If you have not tried these tools up until now, you should do so right now.

Google CodePro AnalytiX

Google CodePro can audit code (find common coding errors), find duplicate code / copy-pasted code, analyse a wide array of code metrix (cyclomatic complexity, LOC, number of fields/parameters, etc), generate test cases, analyse/generate/fix JavaDocs, and analyse dependencies.

pro Quality Tool offers a LOT of functionality
contra Quality Tool only for Eclipse

Recommendation:
If you are using Eclipse, definitely give CodePro a try.

Eclipse Build-In Java Static Code Analysis

Like most IDEs, Eclipse has a build-in static code analyser which can detect bad coding practices. If you want to customize it, go to Window -> Preferences -> Java -> Compiler -> Errors/Warnings.

pro Quality Tool included in Eclipse, so easy to install and configure
pro Quality Tool auto-fix feature
contra Quality Tool only for Eclipse

NetBeans Java Hints – Java Static Code Analysis

NetBeans Java Hints is a build-in static code analysis tool for Netbeans which can detect bad coding practices. If you are using Netbeans, you should also check out the Additional Java hints for NetBeans IDE plugin.

If you want to configure Java Hints, go to Tools -> Options -> Editor -> Hints.

pro Quality Tool included in Netbeans, so easy to install and configure
pro Quality Tool auto-fix feature
contra Quality Tool only for Netbeans

iSpace – Dependency Graph

iSpace creates a dependency graph, showing how your classes and packages are interacting with each other.

pro Quality Tool useful for analyzing dependencies and creating documentation
contra Quality Tool not maintained anymore
contra Quality Tool only for Eclipse

Recommendation:
I really liked this tool, but sadly, it is not maintained anymore. Still, you might want to give it a try.

QJ-Pro: Java Static Code Analysis

QJ-Pro is another tool which can find common bad practices in Java code.

QJ-Pro can be used as a stand-alone tool as well as an Eclipse and Ant plugin (sadly, no Netbeans plugin).

contra Quality Tool not maintained anymore (last update 2005)
contra Quality Tool no Java 8 Support (as of 2015)

Recommendation:
This tool is similar to PMD, but not maintained anymore. Thus, I would not recommend it.

Lint4j – Java Static Code Analysis

Lint4j can analyze Java code to find bad practices.

pro Quality Tool Eclipse Plugin, Stand-Alone, Ant integration

Recommendation:
If you do not like PMD, you might want to give this code quality tool a try.

SonarQube

SonarQube is supposed to be an all-in-one code quality tool. Personally, I could only get the Java static code analysis tool to work.

pro Quality Tool Eclipse Plugin, Stand-Alone, Ant integration
contra Quality Tool complex setup, configuration, and usage

Recommendation:
As I could only get one feature to work, for me, this is just an inferior version of FindBugs. If you want to spend a lot of time trying to set it up and get it to work, you might get more out of it than me.

Further

If the tools listed here aren’t enough for you, you can check out these two extensive lists here and here.

Do you have a favorite Java code analyzer that I forgot to mention? If so, feel free to leave a comment.