Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java coding style

How do you keep yourself coding to standards? There is stylecop and resharper for C#. Are there any tools/eclipse plugins for code analisys in Java? Which of them do you use?

like image 366
George Avatar asked Apr 28 '10 09:04

George


4 Answers

  • Checkout http://checkstyle.sourceforge.net/.

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard. Checkstyle is highly configurable and can be made to support almost any coding standard. An example configuration file is supplied supporting the Sun Code Conventions. As well, other sample configuration files are supplied for other well known conventions.

  • PMD http://pmd.sourceforge.net/

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.

  • Findbugs http://findbugs.sourceforge.net

FindBugs uses static analysis to inspect Java bytecode for occurrences of bug patterns. Static analysis means that FindBugs can find bugs by simply inspecting a program's code: executing the program is not necessary. This makes FindBugs very easy to use: in general, you should be able to use it to look for bugs in your code within a few minutes of downloading it. FindBugs works by analyzing Java bytecode (compiled class files), so you don't even need the program's source code to use it. Because its analysis is sometimes imprecise, FindBugs can report false warnings, which are warnings that do not indicate real errors. In practice, the rate of false warnings reported by FindBugs is less than 50%.

like image 82
miku Avatar answered Oct 18 '22 20:10

miku


Checkstyle and FindBugs and PMD. The latter two are much more than just style tools. But there is usually some effort to be put in, in order to get an agreement among the members of the team and, as well as for configuration of the tool.

like image 31
bertolami Avatar answered Oct 18 '22 19:10

bertolami


In addition to the above, Jalopy is a good tool for formatting the code.

like image 43
JoseK Avatar answered Oct 18 '22 20:10

JoseK


You can have a look at Sonar. It's an open source project that really makes easy the execution of Checkstyle, PMD and Findbugs.

like image 45
Simon Brandhof - SonarSource Avatar answered Oct 18 '22 19:10

Simon Brandhof - SonarSource