Checkstyle Home Page

Checkstyle Logo

Checkstyle

Documentation

SourceForge

Developers

Hosted by: SourceForge Logo

Overview

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.

By default it supports the Sun Code Conventions. However, Checkstyle is highly configurable.

Features

The things that Checkstyle can check for are:

  • Unused or duplicate import statements.
  • Javadoc comments are defined for class, interface, variable and method declarations. Note: This can be made to check only public and protected declarations.
  • Javadoc tags for a method match the actual code.
  • Detect instantiations of classes that should not be instantiated (e.g. java.lang.Boolean).
  • Content of try, catch and finally blocks.
  • Enforce line wrapping on operators.
  • Presence of to-do comments.
  • The package.html package documentation file is available.
  • The file starts with a specified header. This is useful to ensure that a file has a copyright notice.
  • An @author tag exists for class and interface Javadoc comments.
  • Format of variable names match specified regular expressions. For example, can enforce that all static variables must start with "s".
  • Format of class and interface names match a specified regular expression.
  • Format of parameter names match a specified regular expression.
  • Variables that are not declared as private or protected.
  • Order of modifiers matches the recommendation in the Java Language specification.
  • Correct use of white space around binary and unary operators. For example, x -=- 1; is illegal, whereas x -= -1; is not.
  • Periods ('.') are not surrounded by whitespace.
  • Ensure white space follows casts and commas. For example both x = (File)obj and run(arg1,arg2) are illegal, whereas x = (File) obj and run(arg1, arg2) are not.
  • Correct use of white space around parenthesis. For example methodCall( arg1 ) is illegal, whereas methodCall(arg1) is not.
  • Ensure {}'s are used for if/while/for/do constructs.
  • Correct placement of {'s and }'s (same line vs. next line).
  • Lines do not contain tabs.
  • Lines are not longer than a specified length.
  • Methods/Constructors are not longer than a specified number of lines.
  • Files are not longer than a specified number of lines.
  • Long integer literals use an uppercase L. For example 40L instead of 40l.

Download

The latest release of Checkstyle can be downloaded from the SourceForge download page.

If you want to live on the bleeding edge, you can checkout the current development code from CVS and compile yourself.

Related Tools

Checkstyle is most useful if you integrate it in your build process or your development environment. The distribution includes:

  • An Ant task.
  • A command line tool.

Additionally:

If you have written a plugin for other IDEs, like VisualCafé, please let us know, so we can provide a link here.


Copyright © 2001 Oliver Burn. All rights Reserved.