Java Reference
In-Depth Information
It is common practice to include a blank line between an import of standard J2SE pack-
ages, standard J2EE packages, external packages, and internal packages.
Class or Interface Declarations
The Sun Coding Conventions specify that a class or interface declaration should contain some
or all of the following elements in the specified order:
Class/interface Javadoc comments
Class/interface statement
Class variables
Instance variables
Constructors
Methods
Variables should be sorted according to accessibility, from most accessible (public) through to
least accessible (private). For example:
public class VariableOrderExample {
public int aVariableModifiableByAnyOtherClass;
public String anotherPublicVariable;
// protected variables appear after public variables
protected int protectedVariable;
// now list the variables with default access
Character defaultAccessVariable;
// finally list the variables with private access
private int noOtherClassCanSeeMe;
}
Tip Although the location of constants is not specified by the Sun Coding Conventions, common usage is
to list them prior to the class variables.
Methods, on the other hand, should be grouped by functionality rather than scope. This
means you should put a common private method close to the public methods that call it.
Source Code Formatting
While you write your code, you should maintain a consistent approach to the following style
issues:
Indentation
Line lengths/wrapping
Search WWH ::




Custom Search