We all want to write better code. We all appreciate tools that make writing better code easier. And we all want what we want free of charge. So, what does the world of opensource have avaliable to help us java coders write better code?
The good folks at Java-Source.net have compiled a nice page showing many of the choices. I used that as my starting point, surfed around a bit, and decided that three tools work very nicely: PMD, CheckStyles and FindBugs. I found this article by Frank Kelly very helpful.
All three tools work as Eclipse pluggins which is important to me as MyEclipse is my IDE of choice. They install using the Eclipse software update (under the Help menu). See their sites for more details. Once you have the pluggins installed, you go to your project properties and make each one active. Your project will rebuild, and from then on, ever time you save, you’ll see a list of warnings about your code. Right out of the box you’ll have a great set of rules applied to your code that will have you writing better code in no time. Each of them are customizable. You can turn off rules that you don’t care to follow and add rules of your own.
I’ve created an Intro to PMD and Checkstyles Screencast so you can see them in action.
Other helpful resources: