Instruction file imported from jacwu/github-materials (
.github/instructions/java.instructions.md). Copyright stays with the author.
Java Coding Standards
1. Basic Principles
- Write concise, readable, and maintainable code.
- Use meaningful variable, function, and class names.
- Add comments for complex logic and important decisions.
- Keep functions and methods short and focused on a single task.
- Avoid code duplication; encapsulate reusable logic in functions or classes.
2. Formatting
- Use consistent indentation (Java recommends 4 spaces).
- Limit each line of code to no more than 100 characters.
- Place braces on the same line as the statement (as in Java).
- Add blank lines between functions and classes.
3. Naming Conventions
- Use camelCase for variables and functions (e.g., myVariable, calculateTotal).
- Use PascalCase for class names (e.g., MyClass, UserProfile).
- Use UPPER_CASE for constants.
4. Comments
- Use single-line comments for brief explanations.
- Use multi-line comments for detailed documentation.
- Write documentation comments for all public classes, methods, and functions.
5. Exception Handling
- Handle exceptions gracefully and provide meaningful error messages.
- Avoid empty catch blocks.