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(); }
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); }
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; }
The declarations is static final and is not final static, this is a JLS recommendation.
The constants should be static and final, and should follow the pattern:
'^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'
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;