Agent-skills-standard java-best-practices
Apply core Effective Java patterns for robust, maintainable code. Use when applying SOLID principles, choosing between inheritance and composition, refactoring Java code smells, or reviewing class design. (triggers: **/*.java, refactor, SOLID, builder, factory, composition, immutable, Optional, checked exception, clean code)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/java/java-best-practices" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-java-best-practices && rm -rf "$T"
manifest:
skills/java/java-best-practices/SKILL.mdsource content
Java Best Practices
Priority: P1 (HIGH)
Implementation Guidelines
- Immutability: Prefer immutable objects (
fields, unmodifiable collections).final - Access Modifiers: Minimize visibility. Default to package-private (no modifier). Use
for all fields. Onlyprivate
for API contracts.public - Composition > Inheritance: Favor
overHas-A
. Avoid deep hierarchies.Is-A - Constructors: Use Static Factory Methods (
) over complex constructors.User.of() - Builder Pattern: Use for objects with 4+ parameters.
- Exceptions: Recoverable → Checked; Programming error → Unchecked.
- Fail Fast: Validate parameters (
) at method start.Objects.requireNonNull - Interfaces: Code to interfaces (
,List
), not implementations (Map
).ArrayList - Dependency Injection: Inject dependencies via constructor; don't create them internally.
- Method References: Use
overString::toUpperCase
where readable.s -> s.toUpperCase()
Anti-Patterns
- No Null Returns: Return Optional<T> or empty collection instead.
- No Empty Catch: Log or rethrow; never swallow exceptions silently.
- No God Class: Split into focused classes following Single Responsibility Principle.
- No Magic Numbers: Extract named constants with clear meaning.
- No Mutable Statics: Avoid public static mutable fields (global state).