agentsclimarketplace

Java best practices

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

🧠 The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.

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.

What its author says it does

Copied from the file, not written here

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)

SKILL.md

1.9 KB, 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

Keep looking

Skills are one crate of 328,083. 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.