5.4. Statements

5.4.1. If/else

The braces must be used in the if/else blocks, even if there is a single statement. To illustrate:

if (true) {
    doThis();
}

This is not allowed:

 if (true)
     doThis();

The braces position should be the same as in the example before. The following format is incorrect:

if (true) {
    test1();
    test2();
}

5.4.2. Try/catch

All exception required a statement, no silent catching like :

try {
   doThis();
} catch (Exception e) {
    // should not occur
}

You can use a logger :

try {
    doThis();
} catch (Exception e) {
    logger.logDebug("Exception while doing .....", e);
}

5.4.3. Inline Conditionals

The inline conditionals are not allowed. The following code is incorrect:

b = isOk() ? true : false;

The correct way to write is:

if (isOk()) {
    b = true;
} else {
    b = false;
}

5.4.4. Naming conventions

5.4.4.1. Static final attributes

The declarations is static final and is not final static, this is a JLS recommendation.

5.4.4.2. Constants

The constants should be static and final, and should follow the pattern:

'^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'

5.4.4.3. No magic number, use constants

The constants must to be used avoiding magic numbers in the code. For example, it is not allowed:

private int myAttribute = 5;

The correct format is:

/**
 * Default value
 */
private static final int DEFAULT_VALUE = 5;

/**
 * This attribute is initialized with the default value
 */
private int myAttribute = DEFAULT_VALUE;

5.4.4.4. Attribute name

The attribute name should not have a _. The _ is valid for constants that are in uppercase.

You can use pValue, mValue instead of p_Value, m_Value.

The pattern for attribute name is:

'^[a-z][a-zA-Z0-9]*$'