java-21

java-21 is a skill for Claude Code, Codex from Gentleman-Programming/Gentleman-Skills. It costs 35 tokens per session (641 once invoked), scanned A, original, MIT.

A guide to Java 21 features and patterns, including records for immutable data, sealed types for restricted class hierarchies, and virtual threads for blocking input and output.

In plain words
What is it for?
Use it when writing Java 21 code, immutable data objects, closed type hierarchies, or applications using virtual threads.
Why use it?
It helps structure modern Java code safely and consistently when these Java 21 features are appropriate.

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/gentleman-programming/gentleman-skills/java-21
Any agent
npx skills add Gentleman-Programming/Gentleman-Skills --skill java-21
Clone the repo
git clone --depth 1 https://github.com/Gentleman-Programming/Gentleman-Skills

Made for: Claude Code, Codex.

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-21

README.md
[![agentmods](https://agentmods.dev/badge/skills/gentleman-programming/gentleman-skills/java-21.svg)](https://agentmods.dev/skills/gentleman-programming/gentleman-skills/java-21)
Your own site
<a href="https://agentmods.dev/skills/gentleman-programming/gentleman-skills/java-21"><img src="https://agentmods.dev/badge/skills/gentleman-programming/gentleman-skills/java-21.svg" alt="Measured on agentmods" height="20"></a>
Per session 35 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 641 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.00035 $0.00641
Opus 5 $0.00017 $0.00320
Sonnet 5 $0.00007 $0.00128
Haiku 4.5 $0.00003 $0.00064

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

Security

Grade A, and why

java-21 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.

community/java-21/SKILL.md · 122 lines

How it starts

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

When to Use

Load this skill when:

  • Writing Java 21 application or library code
  • Designing immutable DTOs or value objects
  • Modeling closed hierarchies with sealed types
  • Using virtual threads for blocking I/O

Critical Patterns

Pattern 1: Records for immutable data

Use records for DTOs and value objects, validate in compact constructors.

Pattern 2: Sealed types + pattern matching

Use sealed interfaces/classes and switch pattern matching for exhaustiveness.

Pattern 3: Virtual threads for I/O

Use virtual threads to handle blocking I/O without large thread pools.

Code Examples

Example 1: Record with validation

package com.acme.user;

public record Email(String value) {
  public Email {
    if (value == null || !value.contains("@")) {
      throw new IllegalArgumentException("Invalid email");
    }
  }
}

Example 2: Sealed hierarchy + switch pattern matching

package com.acme.payment;

public sealed interface Payment permits Card, BankTransfer { }

public record Card(String last4) implements Payment { }
public record BankTransfer(String iban) implements Payment { }

public final class PaymentPrinter {
  public String describe(Payment payment) {
    return switch (payment) {
      case Card card -> "card-" + card.last4();
      case BankTransfer bank -> "iban-" + bank.iban();
    };
  }
}

Example 3: Virtual threads for blocking calls

package com.acme.io;

import java.util.concurrent.Executors;

public final class Fetcher {
  public void fetchAll(java.util.List<String> urls) throws Exception {
    try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
      for (String url : urls) {
        executor.submit(() -> blockingFetch(url));
      }
    }
  }

  private void blockingFetch(String url) {
    // perform blocking I/O here
  }
}

Anti-Patterns

Don't: Use mutable data carriers

// BAD: mutable DTO
public class UserDto {
  public String name;
  public String email;
}

Read the full file on GitHub · 122 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 · 122 lines · 35 tokens per session scan A 4c04430d5680

Subscribe to this mod's changes

java-21 is a skill published in the GitHub repository Gentleman-Programming/Gentleman-Skills (638 stars, last pushed 5mo ago), licensed MIT. It adds 35 tokens to every session and 641 once invoked, about $0.0002 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-30.

Related

Other skills, from other repositories