Java 21 patterns for records, sealed hierarchies, and virtual threads that keep code immutable and safe.
- CCM score
- 57 of 100
- skills.sh installs
- 334
- GitHub stars
- 681
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers three core patterns: immutable records with compact-constructor validation, sealed types with exhaustive switch matching, and virtual threads for blocking I/O
- Includes worked examples for a validated
Emailrecord, a sealedPaymenthierarchy, and a virtual-thread-per-task fetcher - Flags anti-patterns to avoid, such as mutable public-field DTOs and raw platform threads created per request
- Designed for Java 21 application and library code that models DTOs, closed hierarchies, or blocking I/O
Install
$ npx -y skills add gentleman-programming/gentleman-skills --skill java-21 -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
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 { }
Details
- Repository
- github.com/gentleman-programming/gentleman-skills
- Category
- Java & JVM
- First seen
- Jun 3, 2026
Questions
What does the java-21 skill do?
The java-21 skill teaches an agent Java 21 language and runtime patterns for modern, safe code. It covers records for immutable data with validation in compact constructors, sealed types with switch pattern matching, and virtual threads for blocking I/O.
How do I install the java-21 skill?
Run npx -y skills add gentleman-programming/gentleman-skills --skill java-21 -y inside a project to install the java-21 skill. Once installed, the agent can write Java 21 application and library code using records, sealed types and virtual threads.
Which category does java-21 belong to, and what sets it apart?
The java-21 skill is in the Java and JVM category on Claude Marketplaces and ranks in the top 100 there. It is narrower than the other skills in that category because it focuses only on Java 21 features such as records, sealed hierarchies and virtual threads.
Who is java-21 for?
The java-21 skill is for developers writing Java 21 code who want immutable DTOs and value objects, closed hierarchies modeled with sealed types, or scalable blocking I/O with virtual threads. It also warns against mutable data carriers and raw platform threads per request.
More from gentleman-programming/gentleman-skills
All 13Similar to Java 21
More Java & JVMjava-fundamentalsSkillpluginagentmarketplace/custom-plugin-java638 installsReference guide covering Java 8-21 syntax, OOP, collections, streams, and exception handling with pattern examples.
java-best-practicesSkillleavesfly/jimi164 installsJava coding conventions and common design patterns with code examples for naming, Streams, exceptions, concurrency, and Optional.
142-java-functional-programmingPluginjabrena/plinth467 starsUse when you need to apply functional programming principles in Java — including writing immutable objects and Records, pure functions, functional interfaces, l
144-java-data-oriented-programmingSkilljabrena/plinth398 installsJava refactoring guide that separates records and immutable data from pure transformation and validation functions.
125-java-concurrencySkilljabrena/plinth435 installsJava concurrency guidance covering thread safety, thread pools, async composition, and virtual threads, with compile-first safeguards.
java-expertSkillpersonamanagmentlayer/pcl309 installsExpert Java guidance covering Java 21+ features, Spring Boot, and Maven or Gradle builds with enterprise conventions.