During my search for Profilers I stumbled upon some good Java code checkers or Code Analyzers and though most of you may be already aware about them would like to share my thoughts on the same. Please feel free to correct me or add your inputs to this.
Talking of Code Review or Analysis I wonder if somebody would even think about going for the wearisome task of manually locating lapses in use of Proper Syntax, code indentation, unused variables/imports, naming convention and Javadoc comments without using any automated tool to do the task. Apart from the task of deciding about what code optimizations need be done or detecting any logical blunder rest can perhaps be safely left to these tools. Moreover more ambitious programmers can even look for these tools to operate in tight integration with their favorite IDEs. Fortunately my favorite Netbeans has many modules already available of which three are my personal favorites : PMD, Jalopy and Checkstyle, perhaps in that order.
All the three have various plugins available for various IDEs. Jalopy is a code formatter and beautifier and is highly configurable using code snippets though it does not comprehend well line spacing and tabs for files edited by other IDEs say Kawa or Textpad. Checkstyle is more about code formatting and nit-pickingly looks for white spaces, tabs, position of braces and javadocs and configuration is difficult (as far as I know certainly not configurable through Netbeans GUI). Out of these PMD deserves my high regard, here is a synopsis of what it can detect:
- Unused local variables, parameters and private methods (very useful)
- Empty catch blocks
- Empty ‘if’ statements
- Duplicate import statements
- Classes which could be Singletons
- Short/long variable and method names
A lesser known but very powerful code checking tool is FindBugs. Too bad it has no plugin available for Netbeans though. While the conclusions of the tool about unread fields is not very accurate, it detects what many others don’t such as:
- Null pointer de-reference detector
- Ignored returns from method
- Unclosed I/O streams
- Objecting usage of == or != for String comparison
Here are some other tools:
- SourceMonitor: Provides size and complexity metrics for your source code.
- JLint: A Code verifier
- QStudio also seems pretty good to me. As per their site it is available for download with a year license at no cost.
P.S.: This post finds mention here, here, here and here.