Use descriptive and appropriate names for all identifiers
(variables, method names, class names, constants, etc.).
Comment confusing sections of code.
Be neat.
Identifier Naming and Capitalization
Guidelines
Use descriptive names for all variables, function names, constants,
and other identifiers. Use single letter identifiers only for the
counter in loops.
Variable names start with lower case.
Multi-word identifiers are internally capitalized.
Do not use hyphens or underscores to separate multi-word
identifiers (exception only for those who use speech recognition
software).
Example
Counter Example
Comments: Classes
Guidelines
Every class should be preceded with a descriptive comment using the
“JavaDoc” notational convention. The comment should name the class,
describe its purpose, and name the author.
Example
Comments: Methods
Guidelines
Every method should be preceded with a descriptive comment using the
“JavaDoc” notational convention. The comment should name the method,
describe its purpose, comment all arguments, the return value, and
any exceptions using JavaDoc keywords. (Omit @return and @exception,
if the return value is void or there are no exceptions thrown.)
Example
Comments: Public variables
Guidelines
Every public variable should be preceded with a descriptive comment
using the “JavaDoc” notational convention. The comment should
describe the purpose for the public variable.
Example
Comments: In-line
Guidelines
In-line comments should be used to explain complicated sections of
code, such as loops. Use the // comment delimiter for in-line
comments. Do not comment generally known features of the java
language.
Example
Counter Example
Spacing: Between lines
Guidelines
Use two blank lines to separate each method within a class
definition. Use one blank line to separate logical sections of code
within a method.
Example
Spacing: Within lines
Guidelines
Put a single space before every “{“.
Separate all operators such as “+” with a single space.
Example
Counter Example
Indentation
Guidelines
Indent two spaces when beginning a new block.
Open braces (i.e. “{“) do not start a new line.
Close braces (i.e. “}”) do start a new line, and are indented with the code they close.
Comments line up with the block they comment.
Example
Counter Example
Class, Package, and Method Naming and Capitalization
Guidelines
Classes begin with a capital letter.
Packages are all lower case.
Methods begin with a lower case letter.
Multi-word identifiers are internally capitalized in methods (CamelCase).
Example
Counter Example
Program Modules
Guidelines
Lines of code should be kept short, generally less than 80 or 100 characters wide.
Each public class is contained in a separate file.
Each file has the name of the public class contained within it.