Skip to content

1.1.7 White Spaces

Tomaz Martins edited this page Jul 31, 2015 · 2 revisions

1.1.7.1 Blank Lines

Two blank lines should always be used in the following circumstances:

  • Between sections of a source file.
  • Between classes and interfaces settings.

A blank line should always be used in the following circumstances:

  • Among methods.
  • Between a local variable in a method and its first statement.
  • Before a block comment or a review of a single line.

1.1.7.2 White Spaces

1.1.7.2.1 In statements

In any instruction that makes use of multiple fields separated by commas, put a blank space after the comma.

In any instruction that makes use of parentheses, put a blank space separating the inner contents of the parentheses itself.

public void make ( int arg1, int arg2, String arg3 ) throws EOFException {
     /* Write Instructions Here. */
}

1.1.7.2.2 In Structures

In any structure that makes use of parentheses, put a blank space separating the inner contents of the parentheses itself.

if( condition ) {
    /* Write Instructions Here. */
} else {
    /* Write Instructions Here. 
     * or
     * Nothing To Do.
     */
}
for( int i = 0; i < length; i++ ) {
    /* Write Instructions Here. */
}
do {
    /* Write Instructions Here. */
} while( condition )
switch( sum ) {
    case 1:
        /* Write Instructions Here. */
    case 2:
        /* Write Instructions Here. */
    case 3:
        /* Write Instructions Here. */
    case 4:
        /* Write Instructions Here. */
    default:
        /* Write Instructions Here. */
}
while( condition ) {
    /* Write Instructions Here. */
}
try {
} catch( Exception e ) {
} finally {
}

1.1.7.2.3 In Expressions

In any instruction that makes use of binary operators, put a blank space on both sides of the binary operator.

int a = -4 + 9;
b = a++ / --sum;
c += 4;

In calling methods, put a space and white after opening parenthesis and before closing it unless the parameter list is empty.

surf();

make( books, cookies, children );

String string = new String();
Point point = new Point( x, y );

The use of parentheses in expressions, put a space and white after opening parenthesis and before closing it.

result = ( a * ( b + c + d ) * ( e - f ) );

1.1.7.2.4 At Arrays

In allocating arrays, put a space and white after opening the bracket and before closing it.

The access array elements, put a space and white after opening the bracket and before closing it.

int[] array1 = new int[] { 1, 2, 3 };
int[] array2 = new int[ 3 ];

array2[ 1 ] = array1[ 2 ];