Skip to content
Skills Library
Programming · Building & coding

java

/java

Expert modern Java (Java 17/21 LTS) assistance covering records, pattern matching, virtual threads (Project Loom), Stream API, and JVM memory tuning. Use when writing idiomatic enterprise Java, optimizing garbage collection, or building concurrent backend applications.

Licence
MIT
Last repository change
01.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
2
Deprecation

No signals detected. Repository changed on 01.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Expert modern Java (Java 17/21 LTS) assistance covering records, pattern matching, virtual threads (Project Loom), Stream API, and JVM memory tuning. Use when writing idiomatic enterprise Java, optimizing garbage collection, or building concurrent backend applications.

Original author description

Expert modern Java (Java 17/21 LTS) assistance covering records, pattern matching, virtual threads (Project Loom), Stream API, and JVM memory tuning. Use when writing idiomatic enterprise Java, optimizing garbage collection, or building concurrent backend applications.

How it works

  1. When to Use
  2. Quick Start
  3. Core Concepts
  4. Common Patterns
  5. Best Practices
  6. Troubleshooting
  7. References
Original SKILL.md headings · 161 lines, 668 words
SKILL.md preview
---
name: java
description: Expert modern Java (Java 17/21 LTS) assistance covering records, pattern matching, virtual threads (Project Loom), Stream API, and JVM memory tuning. Use when writing idiomatic enterprise Java, optimizing garbage collection, or building concurrent backend applications.
---

# Java

Modern Java development with Java 17+ features, streams, and enterprise patterns.

## When to Use

- **Enterprise Backend Services & Microservices**: Powering high-throughput Spring Boot, Quarkus, and Micronaut backend APIs.
- **Large-Scale Distributed Systems**: Building infrastructure platforms like Apache Kafka, Hadoop, Spark, and Elasticsearch.
- **High-Concurrency Virtual Threads (Project Loom)**: Handling millions of concurrent network connections without reactive code complexity.
- **Mission-Critical Banking & Payment Gateways**: Processing financial transactions with strict type safety, modularity, and garbage collection tuning.

## Quick Start

```java
// Modern record with validation
public record User(String id, String name, String email) {
    public User {
        Objects.requireNonNull(id, "id must not be null");
        Objects.requireNonNull(name, "name must not be null");
    }
}
```

## Core Concepts

### Virtual Threads (Project Loom - Java 21+ LTS)

Lightweight user-mode threads managed by the JVM rather than the OS, allowing synchronous blocking code to scale to millions of concurrent tasks:

```java
import java.net.URI;
import java.net.http.*;
import java.util.concurrent.Executors;

public class VirtualThreadDemo {
    public static void main(String[] args) {
        // Runs each concurrent task on an ephemeral virtual thread
        try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
            for (int i = 0; i < 10_000; i++) {
                final int taskId = i;
                executor.submit(() -> {
                    // Blocking I/O unmounts virtual thread automatically
                    Thread.sleep(100);
                    return "Task " + taskId + " complete";
                });
            }
        } // Executor awaits completion of all virtual threads
    }
}
```

### Records & Pattern Matching (Java 17/21)

Concise immutable data carriers with expressive pattern matching:

```java
public sealed interface Transaction permits Payment, Refund {}
public record Payment(String transactionId, double amount) implements Transaction {}
public record Refund(String transactionId, double amount, String reason) implements Transaction {}

public class TransactionHandler {
    public static String audit(Transaction tx) {
        return switch (tx) {
            case Payment p when p.amount() > 10_000 -> "Large Payment Audit: " + p.transactionId();
            case Payment p                          -> "Standard Payment: " + p.transactionId();
            case Refund r                           -> "Refund: " + r.reason();
        };
    }
}
```

### Modern Foreign Function & Memory API (Project Panama)

Interacts directly with native C libraries and off-heap memory safely without JNI:

```java
import java.lang.foreign.*;

public class NativeInterop {
    public static void main(String[] args) {
        try (Arena arena = Arena.ofConfined()) {
            MemorySegment nativeString = arena.allocateFrom("Hello Native Memory!");
            System.out.println("Allocated byte size: " + nativeString.byteSize());
        } // Off-heap memory is automatically deallocated here
    }
}
```

## Common Patterns

### Immutable Collection Transformations with Streams

**Problem**: Verbose collection filtering and grouping introducing mutable intermediate states.

**Solution**:

```java
// Immutable collections
var list = List.of("a", "b", "c");
var map = Map.of("key1", "value1", "key2", "value2");

// Stream operations
List<String> names = users.stream()
    .filter(User::active)
    .map(User::name)
    .sorted()
    .toList();

// Collectors grouping
Map<String, List<User>> byRole = users.stream()
    .collect(Collectors.groupingBy(User::role));
```

### Optional

**Problem**: Null reference returns causing unpredictable NullPointerExceptions without compile-time safeguards.

**Solution**:

```java
Optional<User> user = Optional.ofNullable(findUser(id));

String name = user
    .map(User::name)
    .orElse("Unknown");

user.ifPresentOrElse(
    u -> process(u),
    () -> handleMissing()
);
```

## Best Practices

**Do**:

- Adopt Java 21 or 25 LTS: Leverage Virtual Threads, Pattern Matching, Records, and Sequenced Collections.
- Prefer Virtual Threads Over Reactive Complexity: Replace complex WebFlux/RxJava reactive chains with clean synchronous blocking code on virtual threads.
- Use Records for DTOs and Value Objects: Eliminate Lombok boilerplate by using native Java `record`.
- Tune Modern Garbage Collectors: Use ZGC (`-XX:+UseZGC -XX:+ZGenerational`) for sub-millisecond GC pause times on multi-gigabyte heaps.

**Don't**:

- Pool Virtual Threads: Virtual threads are cheap and disposable; create them per task rather than using thread pools.
- Use `synchronized` blocks inside Virtual Threads: Use `ReentrantLock` to avoid pinning virtual threads to OS carrier threads during I/O.
- Return raw `null`: Use `Optional<T>` for return types to force callers to handle absence explicitly.

## Troubleshooting

| Error                             | Cause                      | Solution                         |
| --------------------------------- | -------------------------- | -------------------------------- |
| `NullPointerException`            | Null value access          | Use Optional or null checks      |
| `ClassCastException`              | Invalid type cast          | Use instanceof pattern matching  |
| `ConcurrentModificationException` | Modifying during iteration | Use Iterator.remove() or streams |

## References

- [Java Official Docs](https://docs.oracle.com/en/java/)
- [Baeldung](https://www.baeldung.com/)

Versions

RepositoryScoreLicence
This page · G1Joshi/Agent-Skills100MIT
ericrisco/rsc-harness100MIT
DaraBoth/skilljmskill100MIT
claude-dev-suite/claude-dev-suite100MIT
olehsvyrydov/AI-development-team100MIT
pingqLIN/skill-096MIT
j4flmao/agent-skills95MIT
clawic/skills90MIT

Database snapshot: 13.11.2026 · package version 108daaf71fb2 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100java-expert
    Expert knowledge of Java 25 features including virtual threads, pattern matching, records, sealed classes, value types, and Project Loom/Valhalla features. Use when the user asks about Java programming, Java 25 features, concurrency, performance optimization, or modern Java idioms.
  • 100java-modern-features-virtual-threads
    Use this skill when developing scalable Java applications using Project Loom virtual threads, pattern matching, and record patterns.
  • 100java-language
    Modern Java 21+ language standards including Records, Pattern Matching, and Virtual Threads. Use for Java language constructs or Java-to-Java upgrades; defer Kotlin, tests, formatting/build tools, CompletableFuture, builder patterns, and isolated null-handling questions.
  • 100java-kotlin
    Use when writing modern Java (17+) or Kotlin on the JVM. Covers records, sealed interfaces, pattern matching, coroutines, null safety, and JVM performance and memory tuning. Trigger on "migrate this off java 8 style", "convert this to kotlin coroutines", "jvm keeps running out…
  • 90modernize-java
    Update Java code to modern language features — records, switch expressions, pattern matching, virtual threads, sealed classes, text blocks, and current collection idioms. Triggers on Java source files.
  • 100java-concurrency-jvm-memory
    Use this skill when diagnosing multi-threaded race conditions, volatile visibility, garbage collection tuning, and lock contention in Java.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.