AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Skip to content

19 Modern Java / Lesson 1 of 6

The release train — what changed from Java 9 to 21

13 min · +10 XP · 2 exercises · 5 questions

Read the text13 min
Exercises0/2
Quiz5 q

Quick answer

What's new in Java 17?

Java 17, the long-term-support release of 2021, made sealed classes final and is the first LTS to include everything added since Java 11: records, text blocks, switch expressions, pattern matching for instanceof and helpful NullPointerException messages. Pattern matching for switch was still a preview in 17. With 11 and 21, it is one of the LTS versions production systems run.

For twenty years Java shipped a major version every three to five years, each one enormous. Since 2017 it ships every six months, each release small, with a long-term-support version every two years. Most of the language you have learned in this track — var, records, sealed types, text blocks, switch expressions, pattern matching — arrived on that train, and interviewers now ask "what's new in Java 17?" as routinely as they ask about HashMap. This lesson is the timetable: how the cadence works, what preview means, which versions matter, and a one-screen cheat-sheet of what landed when.

The cadence

  • A feature release every March and September (Java 18, Java 19, …). Each is supported for six months, until the next one.
  • An LTS release every two years since 17 (previously three): 8, 11, 17, 21, next 25. Vendors (Oracle, Eclipse Temurin, Amazon Corretto, Azul, Red Hat) ship security updates for LTS versions for years, which is why production runs on LTS and why "Java 17" and "Java 21" are the versions job adverts name.
  • Features are developed as JEPs (JDK Enhancement Proposals) and often go through preview (complete but subject to change; needs --enable-preview on both javac and java) or incubator (an API module, jdk.incubator.*) before becoming final. Preview code is fine for learning and forbidden in production — it can change or vanish.
  • javac --release 17 compiles against the 17 API and rejects newer syntax, the way to guarantee your code runs on the LTS you target.

Nothing is removed lightly: deprecation for removal (@Deprecated(forRemoval = true)) precedes removal by at least one release, and the JVM warns at run time when you use such an API.

The cheat-sheet

VersionYearLanguageLibrary and JVM
92017private interface methods; diamond with anonymous classes; _ no longer an identifiermodules (JPMS), jshell, List.of/Set.of/Map.of, Stream.takeWhile/dropWhile/iterate(seed, hasNext, next), Optional.ifPresentOrElse/or/stream, Flow (reactive), G1 default, compact strings
102018var for localsList.copyOf, Collectors.toUnmodifiableList, Optional.orElseThrow(), container awareness, parallel full GC for G1
11 (LTS)2018var in lambda parametersHttpClient, String.isBlank/strip/lines/repeat, Files.readString/writeString, Predicate.not, single-file java Hello.java, ZGC (experimental), Epsilon GC; JavaFX and JAXB removed
122019switch expressions (preview)Collectors.teeing, String.indent/transform, Shenandoah
132019text blocks (preview)String.stripIndent, ZGC uncommit
142020switch expressions (final), records (preview), pattern instanceof (preview)helpful NullPointerException messages, JFR streaming; CMS removed
152020text blocks (final), sealed classes (preview)String.formatted, ZGC and Shenandoah production, hidden classes; Nashorn removed
162021records (final), pattern instanceof (final)Stream.toList(), Stream.mapMulti, jpackage, strong encapsulation of JDK internals by default, Unix-domain sockets
17 (LTS)2021sealed classes (final), pattern matching for switch (preview)enhanced pseudo-random generators, macOS/AArch64 port; Applet API deprecated, Security Manager deprecated
182022—UTF-8 by default (JEP 400), simple web server jwebserver, code snippets in Javadoc, finalize deprecated for removal
192022record patterns (preview)virtual threads (preview), structured concurrency (incubator), ExecutorService is AutoCloseable
202023—scoped values (incubator), second previews
21 (LTS)2023pattern matching for switch (final), record patterns (final), unnamed patterns (preview), string templates (preview, later withdrawn), unnamed classes and instance main (preview)virtual threads (final), sequenced collections (getFirst/getLast/reversed), generational ZGC, key encapsulation API
22–242024–25unnamed variables _ (final in 22), statements before super() (preview), primitive patterns (preview), flexible constructor bodiesStructuredTaskScope and scoped values (previews), Foreign Function & Memory API (final in 22), class-file API, stream gatherers (final in 24), Security Manager permanently disabled (24)
25 (LTS)2025module import declarations, compact source files and instance main (final), flexible constructor bodies (final)scoped values (final), stable values (preview), ahead-of-time cache improvements

You do not need every row. You need: 8 (lambdas, streams, Optional, java.time), 11 (var, HttpClient, string methods), 17 (records, sealed, switch expressions, text blocks, pattern instanceof), 21 (pattern switch, record patterns, virtual threads, sequenced collections). Those four LTS milestones are the versions of Java you will actually be asked about.

How to read a JEP

Each JEP page has Summary, Goals, Non-goals, Motivation, Description, Alternatives and Risks. The Motivation and Alternatives sections are where the design rationale lives — why records are not just data classes with less typing, why var was not allowed for fields — and reading two or three (JEP 395 records, JEP 409 sealed, JEP 444 virtual threads) teaches more about Java's design philosophy than any blog post.

Choosing a version in practice

  • New service, no constraints: the latest LTS (21 now, 25 soon).
  • A library: compile with --release set to the oldest version you support; test on the newest.
  • Legacy code on 8: the jump to 11 is the hard one (modules, removed APIs — javax.xml.bind, sun.misc.Unsafe access); 11 → 17 → 21 are mostly smooth.
  • Keep preview features out of main; a --enable-preview build is fine for learning.

Interview angle

  • "What's the release cadence and what is LTS?" Six-monthly feature releases; LTS every two years (8, 11, 17, 21, 25) with multi-year vendor support; production runs LTS.
  • "What's new in Java 17?" Sealed classes final; plus everything since 11: records, text blocks, switch expressions, pattern instanceof, helpful NPEs.
  • "What's new in Java 21?" Pattern matching for switch and record patterns final, virtual threads, sequenced collections, generational ZGC.
  • "What is a preview feature?" Complete but may change; needs --enable-preview; not for production.
  • "Which version added var?" 10 for locals; 11 for lambda parameters.

Key takeaways

  • Six-month releases; LTS 8 → 11 → 17 → 21 → 25; production runs LTS.
  • Preview and incubator features need --enable-preview and stay out of production.
  • 11: var, HttpClient, string methods. 17: records, sealed, switch expressions, text blocks, pattern instanceof. 21: pattern switch, record patterns, virtual threads, sequenced collections.
  • --release N pins the API and syntax you compile against.
  • JEP Motivation sections are the best design documentation Java has.

Common questions

What's new in Java 21?

Java 21, the LTS release of 2023, made pattern matching for switch and record patterns final, and added virtual threads, sequenced collections with getFirst, getLast and reversed, and generational ZGC.

What's new in Java 11?

Java 11, the LTS release of 2018, added the standard HttpClient, string methods such as isBlank, strip, lines and repeat, Files.readString and writeString, var in lambda parameters and single-file launch with java Hello.java. JavaFX and JAXB were removed from the JDK.

How often is a new Java version released?

A feature release ships every March and September and is supported only until the next one. A long-term-support release comes every two years — 8, 11, 17, 21 and 25 — and vendors ship security updates for LTS versions for years, which is why production runs LTS.

What is a preview feature in Java?

A preview feature is complete but may still change or be withdrawn before it becomes final. It must be switched on with --enable-preview for both javac and java, and it belongs in experiments and learning, never in production code.

Which Java version added var?

Java 10 added var for local variables with an initialiser, and Java 11 allowed it in lambda parameters. It is still not allowed for fields, method parameters or return types.

Mark as readSign in to keep your place.

Java Versions Explained: What's New in Java 11, 17 and 21

Java ships a feature release every six months and an LTS every two years: 8, 11, 17, 21, 25. What is new in Java 11, 17 and 21, and what preview features are.

  • Course: Java study plan
  • Module: Modern Java
  • Kind: Lesson
  • Reading time: 13 min
  • Runtime: OpenJDK 18

What's new in Java 17?

Java 17, the long-term-support release of 2021, made sealed classes final and is the first LTS to include everything added since Java 11: records, text blocks, switch expressions, pattern matching for instanceof and helpful NullPointerException messages. Pattern matching for switch was still a preview in 17. With 11 and 21, it is one of the LTS versions production systems run.

Lesson

For twenty years Java shipped a major version every three to five years, each one enormous. Since 2017 it ships every six months, each release small, with a long-term-support version every two years. Most of the language you have learned in this track — var, records, sealed types, text blocks, switch expressions, pattern matching — arrived on that train, and interviewers now ask "what's new in Java 17?" as routinely as they ask about HashMap. This lesson is the timetable: how the cadence works, what preview means, which versions matter, and a one-screen cheat-sheet of what landed when.

The cadence

  • A feature release every March and September (Java 18, Java 19, …). Each is supported for six months, until the next one.
  • An LTS release every two years since 17 (previously three): 8, 11, 17, 21, next 25. Vendors (Oracle, Eclipse Temurin, Amazon Corretto, Azul, Red Hat) ship security updates for LTS versions for years, which is why production runs on LTS and why "Java 17" and "Java 21" are the versions job adverts name.
  • Features are developed as JEPs (JDK Enhancement Proposals) and often go through preview (complete but subject to change; needs --enable-preview on both javac and java) or incubator (an API module, jdk.incubator.*) before becoming final. Preview code is fine for learning and forbidden in production — it can change or vanish.
  • javac --release 17 compiles against the 17 API and rejects newer syntax, the way to guarantee your code runs on the LTS you target.

Nothing is removed lightly: deprecation for removal (@Deprecated(forRemoval = true)) precedes removal by at least one release, and the JVM warns at run time when you use such an API.

The cheat-sheet

VersionYearLanguageLibrary and JVM
92017private interface methods; diamond with anonymous classes; _ no longer an identifiermodules (JPMS), jshell, List.of/Set.of/Map.of, Stream.takeWhile/dropWhile/iterate(seed, hasNext, next), Optional.ifPresentOrElse/or/stream, Flow (reactive), G1 default, compact strings
102018var for localsList.copyOf, Collectors.toUnmodifiableList, Optional.orElseThrow(), container awareness, parallel full GC for G1
11 (LTS)2018var in lambda parametersHttpClient, String.isBlank/strip/lines/repeat, Files.readString/writeString, Predicate.not, single-file java Hello.java, ZGC (experimental), Epsilon GC; JavaFX and JAXB removed
122019switch expressions (preview)Collectors.teeing, String.indent/transform, Shenandoah
132019text blocks (preview)String.stripIndent, ZGC uncommit
142020switch expressions (final), records (preview), pattern instanceof (preview)helpful NullPointerException messages, JFR streaming; CMS removed
152020text blocks (final), sealed classes (preview)String.formatted, ZGC and Shenandoah production, hidden classes; Nashorn removed
162021records (final), pattern instanceof (final)Stream.toList(), Stream.mapMulti, jpackage, strong encapsulation of JDK internals by default, Unix-domain sockets
17 (LTS)2021sealed classes (final), pattern matching for switch (preview)enhanced pseudo-random generators, macOS/AArch64 port; Applet API deprecated, Security Manager deprecated
182022—UTF-8 by default (JEP 400), simple web server jwebserver, code snippets in Javadoc, finalize deprecated for removal
192022record patterns (preview)virtual threads (preview), structured concurrency (incubator), ExecutorService is AutoCloseable
202023—scoped values (incubator), second previews
21 (LTS)2023pattern matching for switch (final), record patterns (final), unnamed patterns (preview), string templates (preview, later withdrawn), unnamed classes and instance main (preview)virtual threads (final), sequenced collections (getFirst/getLast/reversed), generational ZGC, key encapsulation API
22–242024–25unnamed variables _ (final in 22), statements before super() (preview), primitive patterns (preview), flexible constructor bodiesStructuredTaskScope and scoped values (previews), Foreign Function & Memory API (final in 22), class-file API, stream gatherers (final in 24), Security Manager permanently disabled (24)
25 (LTS)2025module import declarations, compact source files and instance main (final), flexible constructor bodies (final)scoped values (final), stable values (preview), ahead-of-time cache improvements

You do not need every row. You need: 8 (lambdas, streams, Optional, java.time), 11 (var, HttpClient, string methods), 17 (records, sealed, switch expressions, text blocks, pattern instanceof), 21 (pattern switch, record patterns, virtual threads, sequenced collections). Those four LTS milestones are the versions of Java you will actually be asked about.

How to read a JEP

Each JEP page has Summary, Goals, Non-goals, Motivation, Description, Alternatives and Risks. The Motivation and Alternatives sections are where the design rationale lives — why records are not just data classes with less typing, why var was not allowed for fields — and reading two or three (JEP 395 records, JEP 409 sealed, JEP 444 virtual threads) teaches more about Java's design philosophy than any blog post.

Choosing a version in practice

  • New service, no constraints: the latest LTS (21 now, 25 soon).
  • A library: compile with --release set to the oldest version you support; test on the newest.
  • Legacy code on 8: the jump to 11 is the hard one (modules, removed APIs — javax.xml.bind, sun.misc.Unsafe access); 11 → 17 → 21 are mostly smooth.
  • Keep preview features out of main; a --enable-preview build is fine for learning.

Interview angle

  • "What's the release cadence and what is LTS?" Six-monthly feature releases; LTS every two years (8, 11, 17, 21, 25) with multi-year vendor support; production runs LTS.
  • "What's new in Java 17?" Sealed classes final; plus everything since 11: records, text blocks, switch expressions, pattern instanceof, helpful NPEs.
  • "What's new in Java 21?" Pattern matching for switch and record patterns final, virtual threads, sequenced collections, generational ZGC.
  • "What is a preview feature?" Complete but may change; needs --enable-preview; not for production.
  • "Which version added var?" 10 for locals; 11 for lambda parameters.

Key takeaways

  • Six-month releases; LTS 8 → 11 → 17 → 21 → 25; production runs LTS.
  • Preview and incubator features need --enable-preview and stay out of production.
  • 11: var, HttpClient, string methods. 17: records, sealed, switch expressions, text blocks, pattern instanceof. 21: pattern switch, record patterns, virtual threads, sequenced collections.
  • --release N pins the API and syntax you compile against.
  • JEP Motivation sections are the best design documentation Java has.

Common questions

What's new in Java 21?

Java 21, the LTS release of 2023, made pattern matching for switch and record patterns final, and added virtual threads, sequenced collections with getFirst, getLast and reversed, and generational ZGC.

What's new in Java 11?

Java 11, the LTS release of 2018, added the standard HttpClient, string methods such as isBlank, strip, lines and repeat, Files.readString and writeString, var in lambda parameters and single-file launch with java Hello.java. JavaFX and JAXB were removed from the JDK.

How often is a new Java version released?

A feature release ships every March and September and is supported only until the next one. A long-term-support release comes every two years — 8, 11, 17, 21 and 25 — and vendors ship security updates for LTS versions for years, which is why production runs LTS.

What is a preview feature in Java?

A preview feature is complete but may still change or be withdrawn before it becomes final. It must be switched on with --enable-preview for both javac and java, and it belongs in experiments and learning, never in production code.

Which Java version added var?

Java 10 added var for local variables with an initialiser, and Java 11 allowed it in lambda parameters. It is still not allowed for fields, method parameters or return types.

Exercises

Modern string toolkit

Read all of standard input. Using only the Java 11+ String methods — lines(), strip(), isBlank(), repeat(), formatted() — print:

  • nonBlank=<number of non-blank lines>
  • stripped=<the non-blank lines, stripped, joined by |>
  • banner=<a line of = as long as the longest stripped line>
  • report=<"%d lines, %d chars".formatted(nonBlank, total characters of the stripped lines)>

Example input (note the surrounding spaces and the blank line)

  hello

 world!!

→

nonBlank=2
stripped=hello|world!!
banner========
report=2 lines, 12 chars

Which release?

Build an immutable lookup table with Map.ofEntries from feature name to the Java version that finalised it: modules 9, var 10, http-client 11, switch-expressions 14, text-blocks 15, records 16, pattern-instanceof 16, sealed 17, pattern-switch 21, record-patterns 21, virtual-threads 21, sequenced-collections 21. LTS versions are Set.of(8, 11, 17, 21). Read an integer n and n feature names; print <feature>: Java <v> (LTS) or (not LTS), or <feature>: unknown.

Example: 3 then records sealed lambdas →

records: Java 16 (not LTS)
sealed: Java 17 (LTS)
lambdas: unknown

In this module: Modern Java

← Checkpoint — I/O, files and time · var and type inference — what the compiler already knows →