| CS2631 - Style Guide 2011 | Updated 2011-01-14
|
| May be updated during the term; suggestions welcome. A dated but useful discussion is at http://192.220.96.201/essays/java-style/. Sun's version is http://developers.sun.com/sunstudio/products/archive/whitepapers/java-style.pdf. |
| 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. Code Layout |
|
2.1 One level of indentation is four spaces or one tab. 2.2 All statements within a block are indented one level. 2.3 Use of braces must be consistent. 2.4 Always use braces in control structures
2.5 Use a space before the opening brace of a control structure's block. 2.6 Use a space around operators. |
| 3. Documentation |
|
3.1 Every class has a Javadoc class comment at the top.
3.2 Every method has a method comment. 3.3 Element comments must be Javadoc-readable.
3.4 Comment code (only) where necessary.
3.5 Block end comments are required for any block of more than a few lines. The following is unreadable:
}
}
}
}
|
| 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 An access modifier is required.
4.4 Where feasible, import classes separately.
4.5 A constructor is required (even if the body is empty). 4.6 A superclass constructor call is required (except for Object).
4.7 Initialize all fields in the constructor. |
| 5. Code idioms |
5.1 Use iterators with collections.
|
Copyright Notice Modified, as permitted, from the BlueJ programming style guide, copyright by Michael Kölling and David Barnes. . |