java-best-practices-modern

java-best-practices-modern is a skill for Claude Code, Codex from maxtrezzi/java-best-practices-skills. It costs 202 tokens per session (5,647 once invoked), scanned A, original, MIT.

A Java coding and review guide for Java 17 and later, with advice selected according to the project's target version.

In plain words
What is it for?
Use it to write, scaffold, refactor, review, audit, or debug substantial Java code, and to decide between Java implementation approaches.
Why use it?
It prevents version mismatches by checking project build files and using guidance appropriate to the Java version instead of assuming the newest features are available.

Skill for Claude CodeCodex

Part of the java-best-practices-modern plugin — 1 skill shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/maxtrezzi/java-best-practices-skills/java-best-practices-modern
Any agent
npx skills add maxtrezzi/java-best-practices-skills --skill java-best-practices-modern
Clone the repo
git clone --depth 1 https://github.com/maxtrezzi/java-best-practices-skills

Made for: Claude Code, Codex.

Or install java-best-practices-modern, the plugin that ships this one along with the rest of its 1 skill.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for java-best-practices-modern

README.md
[![agentmods](https://agentmods.dev/badge/skills/maxtrezzi/java-best-practices-skills/java-best-practices-modern.svg)](https://agentmods.dev/skills/maxtrezzi/java-best-practices-skills/java-best-practices-modern)
Your own site
<a href="https://agentmods.dev/skills/maxtrezzi/java-best-practices-skills/java-best-practices-modern"><img src="https://agentmods.dev/badge/skills/maxtrezzi/java-best-practices-skills/java-best-practices-modern.svg" alt="Measured on agentmods" height="20"></a>
Per session 202 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,647 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00202 $0.05647
Opus 5 $0.00101 $0.02823
Sonnet 5 $0.00040 $0.01129
Haiku 4.5 $0.00020 $0.00565

Measured 4d ago against content hash 49026533fd11, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

java-best-practices-modern scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/java-best-practices-modern/skills/java-best-practices-modern/SKILL.md · 411 lines

How it starts

The opening of the file, as written. The whole thing — 411 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Java Best Practices — Java 17 and later, version-aware

STEP 0 — RESOLVE THE TARGET VERSION, THEN LOAD ITS PROFILE. Resolve the target in this order:

  1. Look for the build file — actively, with your tools. Don't wait for it to be "visible": glob for pom.xml, build.gradle(.kts), gradle.properties, .java-version, .sdkmanrc, then read the one you find for <maven.compiler.release>, JavaLanguageVersion, sourceCompatibility, or a --release flag. In a project directory this almost always resolves the question in two tool calls; asking or assuming when the answer is sitting in the repo is the failure mode.
  2. What the user already said in this conversation (e.g. "we're on 21").
  3. Default to the floor (17), and say which you assumed. Nearly every gap between versions is downgrade-safe: 17-era code compiles and runs on every later version — it is only an older idiom. Writing low and naming the assumption beats guessing high and emitting code that will not compile.

Then load exactly one profile and follow it. Do not re-derive version facts from memory; the profile is the single source of truth for them.

Target Load
17–20 references/profiles/java-17.md
21 references/profiles/java-21.md
22–24 references/profiles/java-21.md — its "not available" table names what finalised when
25 references/profiles/java-25.md
26 and later non-LTS references/profiles/java-latest-nonlts.md

The exception that needs a question, not a default. Final Java APIs stay backward compatible, so the downgrade-safe rule above holds for all of them. Preview APIs are the only ones that can break in both directions — the old spelling fails on the new version and vice versa. Today that is exactly two: StructuredTaskScope (shape changed in 25, Joiners renamed in 26) and StableValue, which became LazyConstant in 26. If the task needs either and you do not know the target, ask — there is no safe default.

Identical on every supported version (17+) — no profile lookup needed:

  • Records (16), sealed interfaces/classes (17), pattern matching for instanceof (16), switch expressions with arrow labels (14), text blocks (15), var (10), Stream.toList() (16).

Everything else — pattern matching for switch, record deconstruction, virtual threads, sequenced collections, gatherers, ScopedValue, structured concurrency — arrived in 21 or later. Check the profile before using it.

Never generate on any supported version, even if a source claims otherwise:

  • with expressions for derived records (obj with { x = 1; }) — not shipped on any version to date. Write an explicit "wither" method calling the canonical constructor, or a copy factory.
  • Null-restricted types (String!, the ! marker) — not shipped on any version to date. Enforce non-null with Objects.requireNonNull in the compact/canonical constructor and JSpecify @NonNull/@Nullable for tooling.
  • String templates (STR."...", StringTemplate, FormatProcessor) — preview on 21 only, then withdrawn: gone from 23 onward, and absent from 25 even with --enable-preview. A dead end that a 21-era source will still recommend. Use formatted/String.format with Locale.ROOT, or a text block.

You are a senior Java engineer. Your job in this skill is to make code that is correct, then clear, then fast — in that order — and to explain the reasoning when it is not obvious. Rules without reasons don't generalize; a junior memorizes rules, a senior knows why each exists and therefore when it bends. Carry that posture into every response.

Two modes. Infer which one applies:

  • GENERATE — the user describes something to build. Write the code.
  • REVIEW — the user shows existing code and asks about it. Audit it.

Read the full file on GitHub · 411 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 411 lines · 202 tokens per session scan A 49026533fd11

Subscribe to this mod's changes

java-best-practices-modern is a skill published in the GitHub repository maxtrezzi/java-best-practices-skills (1 stars, last pushed 8d ago), licensed MIT. It adds 202 tokens to every session and 5,647 once invoked, about $0.0010 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

setup-agentic-scaffolding

Set up the prerequisites for the Quarkus + LangChain4j agentic stack in the coding agent you are running — detect and (with approval) install the toolchain, register the Quarkus Agents MCP and context7 MCP servers, and write the conventions file into your project. User-invoked only, via /setup-agentic-scaffolding; it…

eldermoraes/quarkus-agentic-scaffolding · 97 tokens

does-it-work

Проверка, что продукт реально работает, и защита его качества автотестами. Аудит работающего (в т.ч. навайбкоженного) приложения: найти баги, оценить готовность к проду, выдать баг-репорт с severity. Генерация тестовых фреймворков: API-тесты на Python (pytest + httpx + Pydantic + Allure) и Java (JUnit 5 + REST…

TsakunovR/does-it-work · 295 tokens

language-java

Java idioms — records, sealed types, virtual threads, and JDK 21+ patterns. Auto-load when working with .java files, pom.xml, build.gradle, or when the user mentions Java, JVM, Spring, Maven, Gradle, sealed classes, or virtual threads.

lugassawan/swe-workbench · 61 tokens

standards-java

Java coding standards for enterprise applications. Includes naming conventions, modern Java features, design patterns, and recommended tooling.

b33eep/claude-code-setup · 26 tokens

java-development

Build, review, debug, and maintain production Java applications, libraries, services, and APIs. Use for Java, Spring Boot, Jakarta, Maven, Gradle, JUnit, concurrency, JVM performance, persistence, dependency injection, configuration, resilience, or Java security work.

CODE-SAURABH/OpenSkills · 58 tokens

java-best-practices

Java coding best practices. Use when writing or reviewing Java code (17+). Covers modern features, error handling, and patterns.

Taoidle/plan-cascade · 32 tokens