Java

Java 9 to 21 Features

18 lessons in this section of the Java tutorial. Work through them in order, or jump to the one you need.

  1. 1.Module System (JPMS)

    The Java Platform Module System (JPMS), introduced in Java 9 under Project Jigsaw, adds a module as a new, higher-level unit of code organization above the package…

  2. 2.JShell

    JShell, introduced in Java 9, is an interactive Read-Eval-Print Loop (REPL) bundled directly with the JDK, allowing Java statements, expressions, method, class, and…

  3. 3.Collection Factory Methods

    Collection factory methods — List.of(...), Set.of(...), and Map.of(...)/Map.ofEntries(...) — introduced in Java 9, provide a concise, standard way to create small…

  4. 4.Private Interface Methods

    Private interface methods, introduced in Java 9, allow an interface to declare methods marked private — with a full method body — that are accessible only from within…

  5. 5.var Keyword

    The var keyword, introduced in Java 10 as local variable type inference, lets a local variable declaration omit its explicit type and have the compiler infer it from the…

  6. 6.HTTP Client API

    The java.net.http HTTP Client API, finalized as a standard feature in Java 11 (after an incubating preview in Java 9–10), provides a modern, fluent builder-based client…

  7. 7.String Improvements

    Across Java 11–21, the String class received a steady stream of small, targeted additions — isBlank(), strip()/stripLeading()/stripTrailing(), repeat(int), lines(), and…

  8. 8.Switch Expressions

    Switch expressions, finalized in Java 14 (after preview in Java 12–13), let a switch produce a value directly as an expression, using a new arrow (case L ->) syntax that…

  9. 9.Text Blocks

    Text blocks, finalized in Java 15 (after preview in Java 13–14) and delimited by triple-quotes ("""), let a multi-line string literal be written exactly as it should…

  10. 10.Pattern Matching

    Pattern matching, delivered across several JEPs from Java 16 through Java 21 — pattern matching for instanceof (Java 16), records (Java 16, used heavily by record…

  11. 11.Records

    Records, finalized in Java 16 (JEP 395, after preview in Java 14–15), are a special kind of class declared with the record keyword that compactly defines an immutable…

  12. 12.Sealed Classes

    Sealed classes and interfaces, finalized in Java 17 (JEP 409, after preview in Java 15–16), let a class or interface explicitly restrict, via a permits clause, exactly…

  13. 13.Pattern Matching for switch

    Pattern matching for switch, finalized in Java 21 (JEP 441, after preview across Java 17–20), extends switch's case labels beyond plain constant matching to also support…

  14. 14.Record Patterns

    Record patterns, finalized in Java 21 (JEP 440) alongside pattern matching for switch, extend type patterns specifically for records: rather than only confirming a value…

  15. 15.Sequenced Collections

    Sequenced Collections, finalized in Java 21 (JEP 431), introduce three new interfaces — SequencedCollection, SequencedSet, and SequencedMap — that retrofit a uniform…

  16. 16.Virtual Threads

    Virtual threads, finalized in Java 21 (JEP 444, after preview in Java 19–20) as part of Project Loom, are lightweight threads implemented and scheduled by the JVM itself…

  17. 17.Structured Concurrency

    Structured concurrency, delivered as an incubating/preview API across many JDK releases starting with JEP 428 in Java 19 and still in preview as of Java 25's JEP 505…

  18. 18.Scoped Values

    Scoped Values, finalized in Java 25 (JEP 506, after several preview iterations starting with JEP 429 in Java 20), provide ScopedValue<T> as a mechanism for safely and…