JAVA CODING STANDARDS-III

Sirisha Siri
Jul 25, 2017 · 2 min read

White Spaces:

White spaces means space characters inserted when the space bar or enter key is pressed on the keyboard. The white spaces in Java code provide readability and better understanding of the code.There are four other types of white spaces in Java: the horizontal tab, the form feed, the carriage return, and the linefeed depending on the Operating System(OS).

The concept of white spaces will be discussed on the basis of the following two aspects:
Blank Lines, Blank Spaces

Blank Lines:

The blank lines in Java source code improve readability by arranging the sections of code that are logically related.
Two blank lines are provided between:

Sections of a source file.
The class and interface definition.

Single blank lines are provided:
Between methods.
Between the local variable in a method and its first statement.
Before a block or a single line comment.
Between logical sections within a method to improve readability.

Blank Spaces:

Blank space refer to an extra space between two words provided by pressing the space bar key on the keyboard. The blank spaces should be provided under the following conditions.
A keyword followed by a parenthesis should be separated by a space like this
while (true) {
…..
}
A blank space should be provided after commas in argument lists, like this
public String myarg (a1, a2, a2, a4){
…….
}
All binary operators except ‘.’ should be separated from their operands by spaces. Blank spaces should not separate unary operators, such as minus(-), increment(++), and so on.
x += y + z;
x = (y + z) / (p * q);
The expressions in the for statement should be separated by blank spaces. For exmaple
for ( i = 0; i < 10; i++) {
…..}
Data type of a variable should be followed by a blank space, like
public void newmethod( int x , int y) {
……
}

For more visit www.ktbrain.com