JAVA features from 8 to 21





JAVA features from 8 to 21


JAVA 8

1. Lambda Expressions

2. Functional Interfaces - Interfaces with a single abstract method. Example: Runnable, Comparable

3. Streams API

4. Default and Static Methods in Interfaces

5. Method References - list.forEach(System.out::println);

6. Optional Class

7. New Date and Time API (java.time)


JAVA 9

01. Private Methods in Interfaces - Interfaces can now have private methods to share code between default methods.

interface MyInterface {

    private void log(String msg) {

        System.out.println("Log: " + msg);

    }

}


02. Factory Methods for Collections

New List.of(), Set.of(), and Map.of() methods for creating immutable collections.


03. Stream API Enhancements

New methods: takeWhile(), dropWhile(), and ofNullable()


JAVA 10

Not very important


JAVA 11

1. var in Lambda Parameters

list.forEach((var item) -> System.out.println(item));


2. New String Methods

isBlank(), lines(), strip(), repeat(), etc.


JAVA 16

Records and Pattern Matching for instanceof became standard.

record Point(int x, int y) {}


Java 17

1. Sealed Classes (Standard)

sealed class Shape permits Circle, Square {}


2. Pattern Matching for instanceof (Standard)

if (obj instanceof String s) {

    System.out.println(s.toLowerCase());

}


03. Text Blocks ("""...""") 


Java 21

1. Virtual Threads (Stable)

Lightweight threads managed by the JVM, ideal for high-concurrency applications.

Thread.startVirtualThread(() -> {

    System.out.println("Running in a virtual thread!");

});


2. Pattern Matching for switch (Standard)

switch (obj) {

    case String s -> System.out.println("String: " + s);

    case Integer i -> System.out.println("Int: " + i);

}



Comments

Popular posts from this blog

Database - Topics

02. Spring – Creating spring project clone it with GIT step by step.