20. Coding Conventions

20.6. Statements

 

Declarations

There are two kinds of declaration statements: field declarations, which include a class’s instance variables, and local variable declarations.

 

 

 

 

 

Put one statement per line, possibly followed by an end-of-line comment if the declaration needs explanation.

Initialize local variables when they are declared. Instance variables are given default initializations by Java.

Place variable declarations at the beginning of code blocks in which they are used rather than interspersing them throughout the code block.

 

 

 

 

 

The following class definition illustrates these points:

,,

 

 

 

 

 

 

 

 

 

J