coding-guidelines-java
Installation
SKILL.md
Coding Guidelines (Java/Spring Boot)
Apply these standards to all Java and Spring Boot code. Focus on robustness, maintainability, and best practices.
Section 1: Java Fundamentals (Effective Java)
Class and Object Principles
- Immutability: Minimize mutability. Immutable classes are simpler and safer.
- To create: Provide no setters, make the class
final, make all fieldsfinalandprivate, and make defensive copies of mutable components.
- To create: Provide no setters, make the class
- Composition > Inheritance: Prefer composition over inheritance. Inheritance violates encapsulation.
- Encapsulation: Minimize the accessibility of classes and members. Use
privatewhenever possible. Never expose public fields; use getters. - Interfaces: Prefer interfaces over abstract classes for defining types. Code to the interface, not the implementation (e.g.,
List<String> list = new ArrayList<>()). equals()andhashCode(): Always overridehashCodewhen overridingequals.
Resource Management
try-with-resources: Prefertry-with-resourcesovertry-finallyblocks to ensure proper resource closure (AutoCloseable).- Avoid Finalizers: Do not use
finalizersorcleaners.