Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: s/Brackets/Bracing in section formerly titled "Brackets and Indentation". Clearer wording for one-liner bracing.

...

Types and methods names are NOT abbreviated except for well-known cases such as EOF, Fifo, etc. See Abbreviation Rules for list of currently accepted abbreviations.

...

Braces and Identation

K&R bracket  bracing and indentation style should be used. { starts on the same line as the opening block statement. For example:

Code Block
java
java
while (true) {
    if (false) 
        body();
    else if (true) {
    }
    else {
    }
}

Brackets Braces are required in all cases, even if not required by syntax, except for the cases when next statement is one-liner. The following code does not require brackets.For the latter, braces must not be used, e.g.:

Code Block
if (someCondition)
    a = b + c;

...

When multi-line operator (try-catch, anonymous class instantiation, etc) goes after some condition it is required to use bracketsbraces:

Code Block
if (someCondition) {
    try {
        invocation();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

...