Formatting ConventionsIndent nested code About brackets... Class
public class MyClass{
...
}
Method definitions
void method(int j){
...
}
Loops
for(int i = 0; i<=j; i++){
...
}
If/else statements
if(j<0){
...
}
else if(j>0){
...
}
else{
...
}
Try/Catch/Finally
try{
...
}
catch(Exception e){
...
}
finally{
...
}
Switch
switch(value){
case 0:
...
break;
default:
...
break;
}
White Space |
Naming ConventionsUse meaningful names for your classes and your methods follow the specific conventions mentioned here.
|
JAVADOC style commentsEvery documentation comment begins with: A one-line comment begins with "//"
int iCountPer=0; //counts persons Every class and method should be preceded with a descriptive comment using the "JavaDoc" notational convention. In the class, the comment should name the class, describe its purpose, and name the author.
/**
* Hello1 --- program to print "Hello World".
* @author Blanca Polo
*/
public class Hello1 {
:
}
In the method, the comment should describe its purpose, comment all arguments, the return value, and any exceptions using JavaDoc keywords.
/**
* Prints out "Hello World"
* and the command line arguments.
* @param arg A string array containing
* the command line arguments.
* @exception Any exception
* @return No return value.
*/
public static void main (String[] arg){
:
}
Programming Conventions
|
"No standard is perfect and no standard is universally applicable. Sometimes you will find yourself in a situation where you need to deviate from the established standard. Before you decide to ignore a rule, you should first make sure you understand why the rule exists and what the consequences are if it is not applied. If you decide you must violate a rule, then document why you have done so."*