Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What are the headline features of Java 21 LTS that became final in that release?

The headline features that became final in Java 21 LTS are virtual threads (JEP 444), sequenced collections with SequencedCollection, SequencedSet and SequencedMap (JEP 431), record patterns (JEP 440) and pattern matching for switch (JEP 441). It also added a generational mode for ZGC (JEP 439), which in 21 still had to be enabled with a flag. Structured concurrency, scoped values and unnamed patterns and variables were only previews in 21, so they needed --enable-preview and were not final.

Why this question is asked

Java 21 is the LTS release many organisations moved to from 11 or 17, and it is the first LTS where Java's newer concurrency model and data-oriented style are both final. Interviewers ask this question to check that we know what we can rely on in production and what was still experimental, because using a preview feature in production code means recompiling for every release. In this answer, we will go through each final feature with a short example, then look at the GC change, and finish with what was only in preview.

1Virtual Threads

A platform thread, the kind Java always had, is a thin wrapper around an operating system thread. OS threads are expensive, typically a megabyte of stack reserved and costly context switches, so servers keep them in pools of a few hundred. A virtual thread is a thread managed by the JVM. When it blocks, for example waiting for a database or an HTTP response, the JVM unmounts it from the OS thread it runs on, called its carrier, and runs another virtual thread there. So we can have millions of them, one per task, and keep writing simple blocking code.

Java
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (int i = 0; i < 100_000; i++) {
executor.submit(() -> { Thread.sleep(Duration.ofSeconds(1)); return null; });
}
} // all 100,000 tasks finish in about one second, on a handful of carrier threads
Thread t = Thread.ofVirtual().start(() -> System.out.println("hi"));
System.out.println(t.isVirtual()); // true

Notice that the code is ordinary blocking code; no callbacks or reactive types. Virtual threads help when the work waits on I/O; they do not make CPU-bound work faster.

2Sequenced Collections

Java had no common way to say give me the first or last element. A List used get(0), a Deque used getFirst(), a LinkedHashSet needed an iterator, and its last element needed a full loop. Java 21 added interfaces for collections with a defined order, with methods that work the same on all of them.

Java
List<Integer> list = new ArrayList<>(List.of(1, 2, 3));
list.getFirst(); // 1
list.getLast(); // 3
list.reversed(); // [3, 2, 1], a view, not a copy
LinkedHashSet<String> set = new LinkedHashSet<>(List.of("a", "b", "c"));
set.getLast(); // "c", no loop needed
LinkedHashMap<String, Integer> map = new LinkedHashMap<>();
map.put("x", 1); map.put("y", 2);
map.firstEntry(); // x=1
map.pollLastEntry(); // y=2, removes it

Notice that reversed() returns a view, so changes to the original show through it. SequencedCollection is implemented by List and Deque, SequencedSet by LinkedHashSet and SortedSet, and SequencedMap by LinkedHashMap and SortedMap.

3Record Patterns and Pattern Matching for Switch

Pattern matching for switch lets case labels test types, and record patterns let them take a record apart into its components in the same step. Combined with sealed interfaces, the compiler checks that every case is covered.

Java
sealed interface Shape permits Circle, Rect {}
record Circle(double r) implements Shape {}
record Rect(double w, double h) implements Shape {}
double area(Shape s) {
return switch (s) {
case Circle(double r) -> Math.PI * r * r;
case Rect(double w, double h) when w == h -> w * w; // guard for squares
case Rect(double w, double h) -> w * h;
}; // no default: Shape is sealed
}
area(new Rect(2, 3)); // 6.0

Notice the when clause, called a guard, which adds a condition to a pattern. Switch also gained case null, so we can handle null inside the switch instead of before it.

4Generational ZGC

ZGC keeps pauses around a millisecond on very large heaps. Its original design treated the whole heap alike, but most objects die young, so collecting young objects more often is cheaper. Java 21 added a generational mode that does exactly that, which reduces CPU use and allocation stalls for most workloads. In 21 it was opt-in with -XX:+UseZGC -XX:+ZGenerational. It became the default ZGC mode in 23, and the old non-generational mode was removed in 24.

What was final in Java 21 and what was not
FeatureStatus in 21Final in
Virtual threads (JEP 444)Final21
Sequenced collections (JEP 431)Final21
Record patterns (JEP 440)Final21
Pattern matching for switch (JEP 441)Final21
Generational ZGC (JEP 439)Final, opt-in flagDefault mode from 23
Unnamed patterns and variablesPreview22
Scoped valuesPreview25
Structured concurrencyPreviewStill preview in 25

5What Was Only in Preview

Several features people associate with Java 21 were previews there. Structured concurrency, which treats a group of related subtasks as one unit, was still a preview even in 25. Scoped values, a safer alternative to ThreadLocal for passing context, became final in 25. Unnamed patterns and variables, which let us write _ for a value we do not need, became final in 22. String templates were previewed in 21 and later withdrawn. Using any of them needed --enable-preview at compile and run time, and preview APIs can change between releases, so production code on 21 should not depend on them.

6Follow-up questions

Should we replace all thread pools with virtual threads?

Not blindly. They suit tasks that mostly wait on I/O, such as request handling. CPU-bound pools should stay sized to the number of cores. On 21, synchronized blocks around blocking calls pin the carrier thread, and limited resources like connection pools still need limits, so we test before switching.

Were there smaller additions in 21 worth knowing?

Yes: Math.clamp, StringBuilder.repeat, String.indexOf with a range, Character.isEmoji, and the Key Encapsulation Mechanism API for security. The Foreign Function and Memory API was in its third preview and became final in 22.

Why does preview status matter so much?

A preview feature is complete but can still change or be removed, and class files using it only run on the exact release they were compiled for with --enable-preview. That makes upgrades harder, which is why we wait for final status in production.

7Conclusion

In this answer, we covered the features that became final in Java 21: virtual threads for cheap, blocking-style concurrency, sequenced collections with uniform first, last and reversed operations, and record patterns with pattern matching for switch, which together with sealed types give exhaustive, data-oriented code. We saw that generational ZGC arrived as an opt-in mode, and that structured concurrency, scoped values and unnamed patterns were only previews in 21, so they were not for production use on that release.

What to say in the interviewAbout 80 seconds aloud

Open with

Java 21 has four headline features that are final. First, virtual threads, JEP 444: threads managed by the JVM that unmount from their carrier OS thread when they block, so we can run one thread per request, even millions of them, and keep simple blocking code.

Then, if they want more

They help I/O-bound work, not CPU-bound work. Second, sequenced collections, JEP 431: new interfaces SequencedCollection, SequencedSet and SequencedMap that give every ordered collection getFirst, getLast, addFirst, reversed and, for maps, firstEntry and pollLastEntry, so we no longer need get(0) or an iterator trick on LinkedHashSet.

Third and fourth, record patterns, JEP 440, and pattern matching for switch, JEP 441: case labels can test types, deconstruct records into components and add when guards, and with a sealed interface the switch is checked for exhaustiveness without a default.

On the runtime side, JEP 439 added a generational mode to ZGC, which in 21 you had to enable with -XX:+ZGenerational; it later became the default and then the only mode.

I would also be clear about what was not final in 21: structured concurrency, scoped values and unnamed patterns were previews, needing --enable-preview, so I would not use them in production code on 21. Unnamed variables became final in 22 and scoped values in 25.

About this answer

Last updated
12 November 2026
Versions it names
Java 21
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What are the headline features of Java 21 LTS that became final in that release?": https://scrivio-interview-library.netlify.app/java/java-versions/44fcdac175/