Computer Science Programming Standard

Style Conventions

Capitalization Conventions

In order to maintain readability of code it is important to be able to identify the purpose of an identifier quickly. In the pursuit of this goal Java has adapted the following conventions about capitilization of identifiers.

The first letter of each word in a class name should be capitalized. All other letters should be lower case.

Examples

The first letter of each word of a variable or method should be capitalized, saving the first word. All other letters should be lower case.

Examples

Code Blocks

For purposes of easier readability code blocks such as those contained within while and for loops, if-else statements, and class structures themselves should be indented. These conventions are much easier to illustrate than explain. Indentation should be 2-4 spaces and should be consistent throughout the code.

Examples

One line code block with out braces.
if(x < 5)
   x--;  
One line code block with braces.
if(x < 5)
{ System.out.println("Low Value Obtained"); }

OR

Any of the styles used for multi-line code blocks

Multi-line code bocks
while(!done)
{
    x = getNextValue();
    done = isSmallest(x);
}

OR

while(!done) { 
    x = getNextValue();
    done = isSmallest(x);
}

OR

while(!done)
{ x = getNextValue();
    done = isSmallest(x);
}
Note: Class definition blocks should use only the first or second example.