Tuesday 18 January 2022

Java 11 features

 Few important features captured:

 1) Java 11 is commercialized 

2) Run the java code without compile. It's internally compiles. We no need to compile.

3) Add few String related methods:

1) isBlank ("".isBlank() and  " ".isBlank() ==> returns true)
2)strip(),stripLeading(), stripTrailing() : removes the blank spaces in the string
3)repeat(int) --> "str".repeat(2); ==> outputstrstr

4) Introduced var (Local Variable Type Inference), can't be used in Class level/method parameter level/method return type (for more info : https://www.youtube.com/watch?v=qRuGoUy5fUI)

example: var list = new ArrayList<String>();

5) Java 11 standardizes the Http CLient API. The new API supports both HTTP/1.1 and HTTP/2

6) Java 11 strives to make reading and writing of String convenient.

readString()
writeString()

Example:

Path path = Files.writeString(Files.createTempFile("test", ".txt"), "This is my own text");
System.out.println(path);
String s = Files.readString(path);
System.out.println(s); //output : This is my own text

7) Introduced ChaCha20 and Poly1305 Cryptographic Algorithms. These algorithms will be implemented in the SunJCE provider.

8) Epsilon Garbage collector has been added. It is used for testing performance and memory stress testing. It could also be used for short lived jobs.

9) Supports TLS 1.3 and all other backwards compatibility TLS versions.

10) Collections.toArray(Type) ==> converts the collection to array of Objects.

public class ToArrayEx {
    public static void main(String[] args) {
        List<String> strings = Arrays.asList("ku", "ra", "ga");
        String[] stringArray = strings.toArray(String[]::new);
        System.out.println(stringArray.length);
    }
}

11) Z Garbage collection (experimental, not formalized yet) - It's a low latency garbage collector, can handle Terabytes of heap size.

No comments:

Post a Comment