Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel

Class and Interface Declarations

indent
1
1
When coding Java classes and interfaces, the following formatting rules should be followed:
* No space between a method name and the parenthesis "(" starting its parameter list
* Open brace appears at the end of the same line as the declaration statement
* Closing brace starts a line by itself indented to match its corresponding opening statement, except when it is a null statement the "}" should appear immediately after the "{"
* Methods are separated by a blank line

E.g.,

{code}
class Sample extends Object {
    int ivar1;
    int ivar2;

    Sample(int i, int j) {
        ivar1 = i;
        ivar2 = j;
    }

    int emptyMethod() {}

    ...
}
{code}
Panel

if, if-else, if else-if else Statements

indent
1
1
The if-else class of statements should have the following form:

{code}
if (condition) {
    statements;
}

if (condition) {
    statements;
}
else {
    statements;
}

if (condition) {
    statements;
}
else if (condition) {
    statements;
}
else {
    statements;
}
{code}
Panel

do-while Statements

indent
1
1
A do-while statement should have the following form:

{code}
do {
    statements;
}
while (condition);
{code}

...