Java Version Features

Java has evolved significantly from JDK 1.0 to Java 22, introducing powerful features like lambdas, modules, records, virtual threads, and structured concurrency.

Java Version Highlights

Version | Key Features
Java 8 (2014) | Lambda expressions, Streams API, Optional, Default methods, Nashorn JS engine
Java 9 (2017) | Module system (Project Jigsaw), JShell, Stream improvements
Java 10 (2018) | Local variable type inference (`var`)
Java 11 (2018) | New HTTP Client API, String methods, Flight Recorder, Removed deprecated APIs
Java 12 (2019) | Switch expressions (preview), Shenandoah GC
Java 13 (2019) | Text blocks (preview)
Java 14 (2020) | Records (preview), Pattern matching for instanceof (preview)
Java 15 (2020) | Sealed classes (preview), Hidden classes
Java 16 (2021) | Records, Pattern matching, JEP 376: ZGC improvements
Java 17 (2021) | Sealed classes, Pattern matching, Foreign function & memory API (preview)
Java 18 (2022) | Simple web server, UTF-8 by default, Code snippets in Javadoc
Java 19 (2022) | Virtual threads (Project Loom preview), Structured concurrency
Java 20 (2023) | Scoped values, Record patterns, Pattern matching for switch (preview)
Java 21 (2023) | Finalized virtual threads, Sequenced collections, String templates (preview)
Java 22 (2024) | Second preview of string templates, Stream gatherers, Classfile API (preview)

Core Language Features Across Versions
- Platform Independence: “Write Once, Run Anywhere” via JVM
- Robust & Secure: Strong memory management, exception handling, and security APIs
- Multithreading: Native support for concurrent programming
- High Performance: JIT compiler and optimized garbage collectors
- Object-Oriented: Everything is an object, supporting inheritance, polymorphism, and encapsulation


Concise code samples for key Java features across major versions 

Java 8 – Lambdas & Streams
```java
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
names.stream()
     .filter(n -> n.startsWith("A"))
     .forEach(System.out::println);
```

Java 10 – Local Variable Type Inference (`var`)
```java
var message = "Hello, Java 10!";
System.out.println(message);
```

Java 11 – New HTTP Client
```java
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://example.com"))
    .build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
      .thenApply(HttpResponse::body)
      .thenAccept(System.out::println);
```

Java 14 – Records (Preview)
```java
record User(String name, int age) {}

User user = new User("Sudhamsh", 28);
System.out.println(user.name() + " is " + user.age() + " years old.");
```

Java 17 – Sealed Classes
```java
sealed interface Shape permits Circle, Square {}

final class Circle implements Shape {}
final class Square implements Shape {}
```

Java 19 – Virtual Threads (Project Loom)
```java
Thread.startVirtualThread(() -> {
    System.out.println("Running in a virtual thread!");
});
```

Java 21 – String Templates (Preview)
```java
String name = "Sudhamsh";
int score = 95;
String message = STR."Hello \{name}, your score is \{score}";
System.out.println(message);


Java Version Features

Java8 (LTS) - Java 8 was a massive release
  There’s two main feature
  Lambdas
  functional interfaces
  method references,
  repeating annotations,
  default methods for interfaces
  static methods for interfaces
  Stream API - functional-style operations for collections

Java 9 (Support Ended)
  Collections
    Collections got a couple of new helper methods to easily construct Lists, Sets, and Maps.
      List<String> list = List.of("one", "two", "three");
      Set<String> set = Set.of("one", "two", "three");
      Map<String, String> map = Map.of("foo", "one", "bar", "two");
  Streams
    Streams got a couple of additions, in the form of takeWhile, dropWhile, and iterate methods.
      Stream<String> stream = Stream.iterate("", s -> s + "s").takeWhile(s -> s.length() < 10);
  Optionals
    Optionals got the sorely missed ifPresentOrElse method.
      user.ifPresentOrElse(this::displayAccount, this::displayLogin);
  Interfaces
    Interfaces got private methods:
      public interface MyInterface {
        private static void myPrivateMethod(){
          System.out.println("Yay, I am private!");
        }
     }
  improved try-with-resources statement or diamond operator extensions.
  JShell
    Java got a shell where you can try out simple commands and get immediate results.
  HTTPClient(Preview)
    Java 9 brought the initial preview version of a new HttpClient

Java 10 (Supported Ended)
  garbage collection
  introduction of the var keyword, also called local-variable type inference.
  only applies to variables inside methods
    // Pre-Java 10
    String myName = "Marco";
    // With Java 10
    var myName = "Marco"

Java 11 (LTS) - smaller release
  Strings & Files
    Strings and files got a couple of new methods
      "Marco".isBlank();
      "Mar\nco".lines();
      "Marco ".strip();
  Path path = Files.writeString(Files.createTempFile("helloworld", ".txt"), "Hi, my name is!");
  String s = Files.readString(path);
  Run Source Files
    Starting with Java 10, you can run Java source files without having to compile them first.
    A step towards scripting.
   java First.java
  Local-Variable Type Inference (var) for Lambda Parameters
    (var firstName, var lastName) -> firstName + lastName
    Flight Recorder,
  No-Op Garbage Collector,
  Nashorn-Javascript-Engine deprecated

Java 12 - Java 12 got a couple of new features and clean-ups
  Unicode 11 support
  A preview of the new switch expression

Java 13
  Unicode 12.1 support
  switch statements
  boolean result = switch (status) {
    case SUBSCRIBER -> true;
    case FREE_TRIAL -> false;
    default -> throw new IllegalArgumentException("something is murky!");
  };
Multiline Strings (Preview)
String htmlWithJava13 = """
<html>
<body>
<p>Hello, world</p>
</body>
</html>
""";

Java 14
Pattern Matching for instanceof (Preview)
if (obj instanceof String s) {
// can use s here
} else {
// can't use s here
}
Text Blocks (Second Preview)
Helpful NullPointerExceptions
Java 14 improves the usability of NullPointerException generated by the JVM by describing precisely which variable was null.
Records (Preview)
used as plain immutable data classes for data transfer between classes and applications.
used in places where a class is created only to act as plain data carrier.
public record EmployeeRecord(Long id,
String firstName,
String lastName,
String email,
int age) {
}
Switch Expressions (Standard)
In Java 14, with switch expression, the entire switch block “gets a value” that can then be assigned to a variable in same statement.
It has the support of multiple case labels and using yield to return value in place of old return keyword.
public static Boolean isWeekDay (Day day)
{
Boolean result = switch(day) {
case MON, TUE, WED, THUR, FRI ->
{
System.out.println("It is WeekDay");
yield true;
}
case SAT, SUN ->
{
System.out.println("It is Weekend");
yield false;
}
};
return result;
}

Java 15
Sealed Classes and Interfaces (Preview)
Prior to Java 15, there was no restriction on classes or interfaces regarding which all classes can inherit them.
A sealed class or interface restricts which other classes or interfaces may extend or implement them.
The reserved keyword permits lists all the classes that can extend the sealed class directly. The listed subclasses can either be final, non-sealed, or sealed.sealed class Account
permits CurrentAccount, SavingAccount, LoanAccount {
}
final class CurrentAccount extends Account {}
non-sealed class SavingAccount extends Account {}
sealed class LoanAccount extends Account permits HomeloanAccount, AutoloanAccount {}
final class HomeloanAccount extends LoanAccount{}
final class AutoloanAccount extends LoanAccount{}
EdDSA Algorithm (JEP 339)
EdDSA (Edwards-Curve Digital Signature Algorithm) [RFC 8032] is another additional digital signature scheme added in Java 15 thorough JEP 339.
Hidden Classes
With hidden classes, not framework developers can create non-discoverable classes which cannot be seen by the outside classes; and can be unloaded explicitly without being worrying about possible references from other classes.
Records (Second Preview)
Text Blocks
Removed Nashorn JavaScript Engine
Pattern Matching for instanceof (Second Preview)

Java 16
Java Records and Pattern matching

Java 17 (LTS)
Spring 6 and Spring boot 3 will have first-class support for Java 17.

Java 18
UTF-8 by Default
Simple Web Server

Java 19
UTF-8 by Default
Simp

Java 20 (21 March 2023)
UTF-8 by Default
Simp

Java 21 (LTS) (19 September 2023)
UTF-8 by Default
Simp

Java 22 (19 March 2024)
UTF-8 by Default
Simp

Java 22 (September 2024)
UTF-8 by Default
Simp

Java SE 8 (2014): Introduced lambda expressions, the Stream API, and the new Date-Time API.
Java SE 9 (2017): Added the module system (Project Jigsaw), JShell (interactive REPL), and HTTP Client API.
Java SE 10 (2018): Introduced var for local variable type inference and garbage collector improvements.
Java SE 11 (2018): First long-term support (LTS) release after Java 8, added new string methods and HTTP Client API improvements.
Java SE 12 (2019): Introduced switch expressions (preview) and improved garbage collection.
Java SE 13 (2019): Added text blocks (preview) and dynamic CDS archives.
Java SE 14 (2020): Finalized switch expressions, added records (preview), and pattern matching for instanceof (preview).
Java SE 15 (2020): Sealed classes (preview), hidden classes, and improved text blocks.
Java SE 16 (2021): Finalized records and pattern matching for instanceof, added vector API (incubator).
Java SE 17 (2021): LTS release with sealed classes, foreign function API (preview), and improved garbage collection.
Java SE 18 (2022): Added simple web server and UTF-8 as the default charset.
Java SE 19 (2022): Introduced virtual threads (preview) and structured concurrency (preview).
Java SE 20 (2023): Scoped values (incubator), record patterns (preview), and improved concurrency.
Java SE 21 (2023): LTS release with virtual threads, sequenced collections, and pattern matching for switch.
Java SE 22 (2024): String templates (preview), structured concurrency, and improved memory API.
Java SE 23 (2024): Enhanced primitive type patterns, flexible constructor bodies, and improved module imports.
Java SE 24 (2025): Latest release with updates to concurrency, security, and performance


Comments

Popular posts from this blog

Java 25 Features

Java 8 Programs