Checks for Naming Conventions

Checkstyle supports checking that names in a Java code confirms to specified naming conventions which are specifed as regular expressions. The excellent Jakarta Regexp library is used by Checkstyle.

Format of variable names

The property checkstyle.pattern.member specifies the format for members (non static). Defaults to ^[a-z][a-zA-Z0-9]*$. An example is:

    private int mySize = 0;

The property checkstyle.pattern.const specifies the format for constants (static and final). Defaults to ^[A-Z](_?[A-Z0-9]+)*$. The exception to the rule is for serialVersionUID. An example is:

    public static final int MAX_ROWS = 2;

The property checkstyle.pattern.static specifies the format for static variables (static only). Defaults to ^[a-z][a-zA-Z0-9]*$. An example is:

    private static int numCreated = 0;

The property checkstyle.pattern.publicmember specifies the format for public members (non static public). Defaults to ^f[A-Z][a-zA-Z0-9]*$. This is useful for the fields required for Container Managed Persistence (CMP) Enterprise JavaBeans 1.1. An example is:

    public int fCMPField;

Format of parameter names

The property checkstyle.pattern.parameter specifies the format for parameter names. The default is ^[a-z][a-zA-Z0-9]*$.

Format of type names

The property checkstyle.pattern.type specifies the format for class and interface names. The default is ^[A-Z][a-zA-Z0-9]*$.

Format of method names

The property checkstyle.pattern.method specifies the format for method names. The default is ^[a-z][a-zA-Z0-9]*$.

Format of local variable names

The property checkstyle.pattern.localvar specifies the format for local variables. The default is ^[a-z][a-zA-Z0-9]*$. An example is:

    int localInt = 3;

The property checkstyle.pattern.localfinalvar specifies the format for final local variables. The default is ^[a-z][a-zA-Z0-9]*$. An example is:

    final int finalLocalInt = 3;