The following guidelines should be followed when writing Java code for this project.
- Class Names: Class names should be written in UpperCamelCase. For example:
MyClass
. - Method Names: Method names should be written in lowerCamelCase. For example:
myMethod
. - Variable Names: Variable names should also be written in lowerCamelCase. For example:
myVariable
. - Constant Names: Constant names should be written in all caps with underscores separating words. For example:
MY_CONSTANT
.
- Indentation: Use 4 spaces for indentation. Do not use tabs.
- Braces: Opening braces should be on the same line as the statement that begins the block. Closing braces should be on a new line.
- Line Length: Each line of code should be no longer than 80 characters.
- Spacing: There should be a space after keywords (
if
,for
,while
, etc.) and between operators (+
,-
,=
, etc.).
- Class Comments: Every class should have a comment that describes what the class does.
- Method Comments: Every method should have a comment that describes what the method does, its parameters, and its return value (if any).
- In-line Comments: In-line comments should be used sparingly and only to clarify complex code.
- Use Standard Libraries: Whenever possible, use standard libraries instead of writing your own code.
- Avoid Magic Numbers: Do not use "magic numbers" (hard-coded numerical values) in your code. Instead, define constants for these values.
- Error Handling: Handle errors and exceptions appropriately. Do not ignore or suppress them.
Here is an example of Java code that follows these guidelines:
public class MyClass {
/**
* This method does something.
*
* @param param1 The first parameter.
* @param param2 The second parameter.
* @return The result of the operation.
*/
public int myMethod(int param1, int param2) {
int result = param1 + param2;
if (result > 10) {
result = 10;
}
return result;
}
}
These guidelines should be followed as closely as possible to ensure consistency throughout the codebase.