Thursday, August 25, 2011

Java Tools: Source Code Optimization and Analysis

Below is a list of some tools that can help you examine your Java source code for potential problems:


1. PMD from http://pmd.sourceforge.net/

License: PMD is licensed under a "BSD-style" license

PMD scans Java source code and looks for potential problems like:

* Possible bugs - empty try/catch/finally/switch statements
* Dead code - unused local variables, parameters and private methods
* Suboptimal code - wasteful String/StringBuffer usage
* Overcomplicated expressions - unnecessary if statements, for loops that could be while loops
* Duplicate code - copied/pasted code means copied/pasted bugs

You can download everything from here, and you can get an overview of all the rules at the rulesets index page.

PMD is integrated with JDeveloper, Eclipse, JEdit, JBuilder, BlueJ, CodeGuide, NetBeans/Sun Java Studio Enterprise/Creator, IntelliJ IDEA, TextPad, Maven, Ant, Gel, JCreator, and Emacs.

2. FindBug from http://findbugs.sourceforge.net/

License: L-GPL

FindBugs, a program which uses static analysis to look for bugs in Java code. And since this is a project from my alumni university (IEEE - University of Maryland, College Park - Bill Pugh) , I have to definitely add this contribution to this list.

3. Clover from http://www.cenqua.com/clover/

License: Free for Open Source (more like a GPL)

Measures statement, method, and branch coverage and has XML, HTML, and GUI reporting. and comprehensive plug-ins for major IDEs.

* Improve Test Quality
* Increase Testing Productivity
* Keep Team on Track

Fully integrated plugins for NetBeans, Eclipse , IntelliJ IDEA, JBuilder and JDeveloper. These plugins allow you to measure and inspect coverage results without leaving the IDE.

Seamless Integration with projects using Apache Ant and Maven. * Easy integration into legacy build systems with command line interface and API.

Fast, accurate, configurable, detailed coverage reporting of Method, Statement, and Branch coverage.

Rich reporting in HTML, PDF, XML or a Swing GUI

Precise control over the coverage gathering with source-level filtering.

Historical charting of code coverage and other metrics.

Fully compatible with JUnit 3.x & 4.x, TestNG, JTiger and other testing frameworks. Can also be used with manual, functional or integration testing.