Skip to content
alyn
Gentleman-Programming

Java 21 skill

Java 21 language and runtime patterns for modern, safe code. Trigger: When writing Java 21 code using records, sealed types, or virtual threads.

$npx skills add Gentleman-Programming/Gentleman-Skills --skill java-21
View this skill on GitHubGentleman-Programming/Gentleman-Skills/community/java-21/SKILL.md
Pack stars
665
Pack installs
5.6k
Alyn Score
41/99
Updated
8 months ago
License
MIT
– views – installs via Alyn

Gentleman-Programming

Java 21

Install Java 21

Pick your agent. Every command is ready to paste.

$npx skills add Gentleman-Programming/Gentleman-Skills --skill java-21

The open skills CLI detects your agents (Claude Code, Cursor, Codex and 70+ more) and installs to the right folder. Add -g to install globally.

01

Install it

Run the command above, or upload the folder in Claude.

02

Ask naturally

Describe the task. Your agent loads java-21 when the request matches its description.

03

Name it if needed

If it does not trigger, say “use the java-21 skill”. In Codex, type $java-21.

The skill itself

SKILL.md

FolderGitHub

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;
}

Don't: Spin up raw platform threads per request

// BAD: expensive and unbounded
new Thread(() -> blockingFetch("https://api" )).start();

Quick Reference

Task Pattern
Immutable DTOs Use records with validation
Closed hierarchies Use sealed interfaces + switch
Blocking I/O scale Use virtual threads executor

Resources

Tips for Java 21

  • • Start a fresh session after installing so your agent picks up the new skill.
  • • It is part of a pack with 24 skills. Install only the ones you need with --skill to keep triggers precise.
  • • If two skills overlap, mention the one you want by name.

Questions about Java 21

What does the Java 21 skill do?

Java 21 language and runtime patterns for modern, safe code. Trigger: When writing Java 21 code using records, sealed types, or virtual threads.

How do I install Java 21?

Run "npx skills add Gentleman-Programming/Gentleman-Skills --skill java-21" in your project. The skills CLI installs it for Claude Code, Cursor, Codex and 70+ other agents. In Claude on the web, upload the skill folder as a ZIP under Customize > Skills.

Does Java 21 work in Cursor and Codex?

Yes. Java 21 uses the open SKILL.md format, so it works in Claude Code, Claude, Cursor, OpenAI Codex, Gemini CLI, GitHub Copilot and other agents that support agent skills.

Is Java 21 free?

Java 21 is open source on GitHub under the MIT license. It is free to install; check the license before commercial use.

Who made Java 21?

Java 21 is published by Gentleman-Programming in the Gentleman-Programming/Gentleman-Skills repository, together with 23 other skills.

Similar skills. From other creators.