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
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
Post a Comment