agentleFS
oouooouo/skills/java-best-practices/SKILL.md

java-best-practices

Skill1 starsChanged 3 months agoMITView on GitHub

Use when writing, modifying, debugging, or reviewing Java source or tests, or answering questions about Java behavior. Relevant .java files can establish the language when the request omits it. Covers Google Java formatting, comments, JDK compatibility, and defensive coding. Skip build-only tasks.

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

18 rules. 0 are common, 13 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 13

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the Google Java Style Guide for style, the Alibaba Java Development Manual for defensive coding, and the target JDK's contracts for …

    line 14
  2. Distinctive:

    Read the applicable repository instructions, nearby code, and target module's build settings.

    line 31
  3. Distinctive:

    Check the compiler release or, where set separately, the source and target levels.

    line 32
  4. Distinctive:

    Treat names and existing comments as leads to verify.

    line 46
  5. Distinctive:

    When evidence is missing, narrow the claim or mark it unverified.

    line 47
  6. Distinctive:

    Read every reference section that applies, including when one expression involves several contracts (for example, decimal equality in a map …

    line 60
  7. Distinctive:

    Use early returns or continues for exceptional cases.

    line 77
  8. Distinctive:

    Follow explicit user and repository rules.

    line 80
  9. Very specific:

    Use / ... */ Javadoc for class, field, and method declaration comments, including non-public members.

    line 81
  10. Very specific:

    Put implementation-specific rationale beside the relevant statements inside the method, using // or /* ...

    line 84
  11. Distinctive:

    Document units, nullability, and boundaries of public and protected APIs in Javadoc.

    line 89
  12. Very specific:

    Add @author and @since when the project's or user-designated reference's convention calls for them.

    line 91
  13. Distinctive:

    Ask only when a required value cannot be established.

    line 94
  14. Very specific:

    Use explicit imports, conventional modifier order, braces around control-flow bodies, and uppercase L for long literals.

    line 95
  15. Very specific:

    Use the repository's configured google-java-format task or pinned formatter within that scope.

    line 104
  16. Distinctive:

    Check new, edited, and affected existing comments against the inspected behavior and the project's form, placement, language, and …

    line 117
  17. Distinctive:

    When changing this skill's behavior, use the isolated cases in evals/README.md.

    line 131
  18. Distinctive:

    Keep evaluation prompts and grading criteria out of ordinary Java task context.

    line 132

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Java Best Practices

Overview

Use the Google Java Style Guide for style, the Alibaba Java Development Manual for defensive coding, and the target JDK's contracts for runtime behavior. For attribution or conflicting guidance, consult the source notes.

When to Use

  • For implementation, debugging, and Java comment or Javadoc edits, follow the target module's conventions and limit edits to the requested scope. Standalone documentation, build, and deployment tasks are outside scope.
  • For a review, keep the worktree read-only and apply the rules relevant to the diff.
  • For a Java behavior question, go directly to the relevant contract. Ask for the JDK version only when it changes the answer and the target release cannot be inferred.

Instructions

Establish the baseline

Read the applicable repository instructions, nearby code, and target module's build settings. Check the compiler release or, where set separately, the source and target levels. Use those settings with the module's toolchain and runtime requirements to select APIs and language features. Keep the existing release and preview settings. Check unfamiliar APIs against documentation for that release. Preserve established API, serialization, framework, and nullability contracts.

Establish evidence for behavior claims

  • For behavior changes and semantic comments, distinguish intended behavior from current behavior. Derive expectations from the user's requirement or an established contract; inspect implementation paths and observed checks to establish current behavior.
  • Support non-obvious claims, such as no side effects, idempotency, nullability, or thread safety, with an inspected source location, relevant check, or version-specific contract. Trace applicable normal, no-op, and failure paths through helpers, including state changes before a return or throw. Treat names and existing comments as leads to verify.
  • When evidence is missing, narrow the claim or mark it unverified. Resolve uncertainties that affect correctness before making a change that depends on them; continue independent work.

Apply the rules that match the change

For changes affecting behavior, signatures, or result use, trace relevant callers and check how return values affect application behavior. Retain return information required by that behavior or an established contract; otherwise simplify within the task scope. Verify compatibility from actual consumers and integration requirements, not visibility alone. If external consumers or reflective/framework entry points cannot be checked, preserve the existing contract and report the compatibility limit; an empty local search does not establish that a contract is unused.

Read every reference section that applies, including when one expression involves several contracts (for example, decimal equality in a map key).

  • For decimal precision and equality, boxed values, bean names, enum metadata, null, or Optional, read Values and API contracts.
  • For collection construction, mutability, null elements, iteration, arrays, views, or lookup, read Collections.
  • For string accumulation or delimited fields, read Text.
  • For executors, virtual threads, thread-local context, or parallel streams, read Concurrency.
  • For switches, text blocks, records, patterns, or sealed types, read Language features.
  • For failure signaling, exception handling, closing, unlocking, interruption, or logging, read Resources and failures.

Structure and document Java code

  • Use early returns or continues for exceptional cases. Split independent business steps into action-named methods. Name intermediate values, business thresholds, and sentinel values.
  • Inspect any user-named reference class for comment language, terminology, and level of detail. Follow explicit user and repository rules; otherwise apply the comment forms below.
  • Use /** ... */ Javadoc for class, field, and method declaration comments, including non-public members. Describe class responsibilities, field semantics, and method contracts; include threading requirements, idempotency, and boundary behavior where relevant.
  • Put implementation-specific rationale beside the relevant statements inside the method, using // or /* ... */. Preserve caller-visible constraints when shortening comments.
  • Explain business rules, units, and exceptional boundaries in the project's comment language with English half-width punctuation and the project's sentence-ending convention. Explain non-obvious field units, special values, collection keys/values, and array indexes as needed. Document units, nullability, and boundaries of public and protected APIs in Javadoc. Reuse inherited documentation and omit redundant descriptions of obvious accessors.
  • Add @author and @since when the project's or user-designated reference's convention calls for them. Verify values for the target class or change; matching a reference's style does not establish its author or release as the values for this change. Ask only when a required value cannot be established; never invent an author or release.
  • Use explicit imports, conventional modifier order, braces around control-flow bodies, and uppercase L for long literals. Group overloads and constructors, use @Override where legal, qualify static members with their class, and keep type-use annotations with their type.
  • Reserve UPPER_SNAKE_CASE for deeply immutable static final constants. Use lowerCamelCase for loggers and mutable static final objects.

Format changed handwritten Java files

  1. Select only changed handwritten Java files. Leave generated sources to their generator.
  2. Use the repository's configured google-java-format task or pinned formatter within that scope. If no formatting task is configured, check build scripts and local tooling for an existing google-java-format CLI. Verify the actual executable with --version and --help.
  3. Let the formatter handle wrapping, two-space indentation, K&R braces, and the Google Style 100-column limit with its documented exceptions. Use its check mode when available. Otherwise, compare its stdout with each selected file. Inspect the diff for unrelated edits.

Verify and report

  • For behavior changes, choose a targeted check that distinguishes the required outcome from a plausible wrong one. Check state changes and failure effects when relevant, as well as return values. Use the independently established expectation above; copying the implementation into an assertion does not validate its behavior. Run the relevant compilation, tests, and static checks.
  • Check new, edited, and affected existing comments against the inspected behavior and the project's form, placement, language, and punctuation rules. For comment-only or formatting-only edits, limit verification to those changes and required project checks; no full test workflow is needed.
  • Finish by accounting for each affected contract and semantic claim: it has supporting evidence and an observed relevant check, or an explicit unverified boundary. For comments, source inspection can be that check. Claim a runtime behavior was verified only when an executed check covered it; formatting and compilation alone do not establish behavior.
  • Report the change, decisive evidence, actual check results, and remaining limits, including unavailable formatting or tests. Keep this concise; no separate evidence report is required.
  • For review findings, give the location, failure condition, impact, and repair. Distinguish correctness defects from style violations. Report in the user's language.

Skill maintenance

When changing this skill's behavior, use the isolated cases in evals/README.md. Keep evaluation prompts and grading criteria out of ordinary Java task context.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.