java-best-practices-java11

A coding and review guide for Java 11, a long-term-support version of Java, with rules that keep code compatible with that version.

In plain words
What is it for?
It helps write or review substantial Java 11 code using alternatives to newer features such as records, sealed classes, pattern matching, text blocks, and virtual threads.
Why use it?
It prevents newer Java features from being suggested or added to projects that must run on Java 11.

Skill for Claude CodeCodex

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-java11
Any agent
npx skills add maxtrezzi/java-best-practices-skills --skill java-best-practices-java11
Clone the repo
git clone --depth 1 https://github.com/maxtrezzi/java-best-practices-skills

Made for: Claude Code, Codex.

Per session 277 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,398 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.00277 $0.04398
Opus 5 $0.00138 $0.02199
Sonnet 5 $0.00055 $0.00880
Haiku 4.5 $0.00028 $0.00440

Measured yesterday against content hash df2dc00d1c4b, 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-java11 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 yesterday.

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-java11/skills/java-best-practices-java11/SKILL.md · 318 lines

How it starts

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

Java Best Practices — Java 11 (LTS) Edition

TARGET: JAVA 11. Every construct in this skill must compile and run on a stock JDK 11 with no preview flags. The features below DO NOT EXIST in Java 11 and must never appear in generated code, nor be recommended in a review as the "modern" fix:

  • record (Java 16) — use a final class with final fields, an all-args constructor, explicit equals/hashCode/toString, and accessors.
  • sealed interfaces/classes (Java 17) — emulate a closed set with a package-private abstract base or an enum, and document the closed set.
  • Pattern matching for instanceof (Java 16) — write the explicit instanceof test followed by a cast.
  • Pattern matching / arrow switch expressions (switch expr Java 14, patterns Java 21) — use a classic switch statement or an if/else if chain; assign the result to a variable explicitly.
  • Text blocks (""", Java 15) — use ordinary quoted strings with explicit \n and concatenation, or String.join.
  • Virtual threads, Structured Concurrency, Scoped Values (Java 21+) — use a platform-thread ExecutorService sized to the workload.
  • Unnamed variables _ (Java 21+) — name the variable, prefix unused with a comment.

What you DO have on Java 11 and should use: var for locals (Java 10), Optional, the full Streams API, unmodifiable factory methods List.of / Map.of / Set.of (Java 9), Collectors.toUnmodifiableList (Java 10), String.strip/isBlank/repeat/lines (Java 11), Files.readString / writeString (Java 11), the java.net.http.HttpClient (Java 11), Optional.isEmpty (Java 11), and Collection.toArray(IntFunction) (Java 11). If a reference file shows a record, sealed type, or pattern switch, mentally translate it to the Java 11 equivalent above before applying it.

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.

When both apply (e.g. "rewrite this"), generate the improved version first, then briefly justify the decisions that changed.


Read the full file on GitHub · 318 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. yesterday First seen · 318 lines · 277 tokens per session scan A df2dc00d1c4b

Subscribe to this mod's changes

java-best-practices-java11 is a skill published in the GitHub repository maxtrezzi/java-best-practices-skills (1 stars, last pushed 5d ago), licensed MIT. It adds 277 tokens to every session and 4,398 once invoked, about $0.0014 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.