Program Style Guide | Version 1.2
|
A good article on style is Good Java Style: Part 1 by Thornton Rose. |
1. Naming |
1.1 Use meaningful names.
1.2 Class names start with a capital letter. 1.3 Class names are singular nouns. 1.4 Method and variable names start with lowercase letters.
1.5 Constants are written in UPPERCASE.
|
2. Layout |
2.1 One level of indentation is four spaces. 2.2 All statements within a block are indented one level. 2.3 Braces for classes and methods are alone on one line.
2.4 For all other blocks, braces open at the end of a line.
2.5 Always use braces in control structures
2.6 Use a space before the opening brace of a control structure's block. 2.7 Use a space around operators. 2.8 Use one or two blank lines between methods (and constructors).
|
3. Documentation |
3.1 Every class has a class comment at the top.
3.2 Every method has a method comment. 3.3 Comments are Javadoc-readable.
3.4 Code comments (only) where necessary.
|
4. Language use restrictions |
4.1 Order of declarations: fields, constructors, methods.
4.2 Fields may not be public (except for final fields). 4.3 Always use an access modifier.
4.4 Import classes separately.
4.5 Always include a constructor (even if the body is empty). 4.6 Always include superclass constructor call.
4.7 Initialise all fields in the constructor. |
5. Code idioms |
5.1 Use iterators with collections.
|