[prev][next]
8- White Space
8.1 Blank Lines
Blank lines improve readability by setting off sections of code that are logically related.
Two blank lines should always be used in the following circumstances:
between sections of a source file
between class and interface definitions
one blank line should always be used in the following circumstances:
between methods
between the local variables in a method and its first statement
before a block (see section 5.1.1)or single-line(see sectgion 5.1.2) comment
between logical sections inside a method to improve readability
8.1 Blank spaces
blank spaces should be used in the following circumstances:
A keyword followed by a parenthesis should be separated bya space. Example:
while (true) {
...
}
note that a blank space should not be used between a method name and its opening
parenthesis. this helps to distinguish keywords from method calls.
a blank space should appear after commas in argument lists.
all binary operators except. should be separated from their operands by spaces. blank
spaces should never separate unary operators such as unary minus, increment("++"),and
decrement ("--") from their operands.example:
a += c + d;
a = (a +b) / (c * d);
while (d++ = s++) {
n++;
}
prints("size is " + foo + "\n");
the expression in a for statement should be separated by blank spaces.examples:
for (expr1; expr2; expr3)
casts should be followed by a blank space. examples:
mymethod ((byte) anum, (object0 x);
mymethod ((int) (cp + 5), ((int) (i + 3))
+1);