next up previous
Next: Method naming Up: Naming Convention Previous: Class/Interface Naming

Field Naming

Names of non-constant fields (reference types, or non-final primitive types) should use the infixCaps style. Start with a lower-case letter, and capitalize the first letter of any subsequent word in the name, as well as any letters that are part of an acronym. All other characters in the name are lower-case. Do not use underscores to separate words. The names should be nouns or noun phrases. Examples:

    boolean resizable;
    char recordDelimiter;
    final pointOrigin = new Point(0, 0); // final, but reference type

Names of constant fields (final, primitive type fields) should be all upper-case, with underscores separating words. Remember that all interface fields are inherently final. Examples:

    MIN_VALUE
    MAX_BUFFER_SIZE
    OPTIONS_FILE_NAME

One-character field names should be avoided except for temporary and looping variables. In these cases, use:

    b for a byte
    c for a char
    d for a double
    e for an Exception object
    f for a float
    g for a Graphics object
    i, j, k, m, n for integers
    p, q, r, s for String objects

An exception is where a strong convention for the one-character name exists, such as x and y for screen coordinates.



Dennis Seah Mon Jul 17 11:43:42 2006