| Purpose | Coding Standard of Java Programs |
| Program Headers | All programs should begin with a descriptive header |
| Header Format |
/** * Title: Program Name * * Description: Description of the program * @Author: My Name * @Version: Number * */ |
| Listing Contents | List a summary of the contents |
| Contents Example |
/* Contents: Reuse Instructions Compilation Instructions */ |
| Reuse Instructions | Description of how the program/function is used |
| Reuse Example |
/* * Function: static void FunctionName(Type parameter) * * Description: This function does this and that, then outputs something else. * * Returns: Some Result * [[Personalized item]] */ |
| Variable names | Descriptive names for variables. First word of var names start with lower case and subsequent words start with upper case |
| Variable Example | int sumObjectArray = 0; |
| Class Names | Descriptive Names for Class names. Class name's first word and subsequent words start with upper case |
| Class Names Example | public class FunctionName |
| Function Names | Descriptive names for Function names. Function name's first word start with lower case and subsequent words start with upper case |
| Function Names Example | int makeRange (int lower, int upper) |
| Comments |
Include comments for variable names to indicate their purpose Comment the functions as stated in reuse instructions to understand its operation Comment the logic to indicate their purpose |
| Comment Example |
int sumObjLoc = 0; // To hold the sum value of list of objloc while (parser.hasMoreTokens()) // have all the tokens been taken into account |
| Blank Spaces |
A blank line between var declaration and start of the logic A blank line between the end of a function and start of another |
| Indenting |
Indent every level of brace from previous one Open and close braces should be on own lines and aligned with each other |
| Indenting Example |
int[] makeRange(int lower, int upper) { int[] arr = new int[(upper - lower) + 1]; for(int i = 0; i < arr.length; i++) { arr[i] = lower++; } return arr; } |
| LOC |
All curly braces are to be on separate lines All logic statements are to be on separate lines |