agentsclimarketplace

Java best practices

Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/java-best-practices

Core Effective Java patterns for robust, maintainable Java 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)From its SKILL.md

Install
npx -y skills add ComeOnOliver/skillshub --skill java-best-practices

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

1.9 KB, 324 tokens by cl100k_base, as published. Nobody here has run it

Java Best Practices

Priority: P1 (HIGH)

Core engineering principles for robust, maintainable Java systems.

Implementation Guidelines

  • Immutability: Prefer immutable objects (final fields, unmodifiable collections).
  • Access Modifiers: Minimize visibility. Default to package-private (no modifier). Use private for all fields. Only public for API contracts.
  • Composition > Inheritance: Favor Has-A over Is-A. Avoid deep hierarchies.
  • Constructors: Use Static Factory Methods (User.of()) over complex constructors.
  • Builder Pattern: Use for objects with 4+ parameters.
  • Exceptions: Recoverable → Checked; Programming error → Unchecked.
  • Fail Fast: Validate parameters (Objects.requireNonNull) at the method start.
  • Interfaces: Code to interfaces (List, Map), not implementations (ArrayList).
  • Dependency Injection: Inject dependencies via constructor; don't create them internally.
  • Method References: Use String::toUpperCase over s -> s.toUpperCase() where readable.

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).

References

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.