Java 11 Features
HTTP Client API
Java 11 introduced the standardized HTTP Client API (module java.net.http, package java.net.http) as part of JEP 321, replacing the legacy HttpURLConnection with a modern, flexible, and feature-rich API. It supports HTTP/1.1, HTTP/2, WebSocket, and both synchronous and asynchronous requests, eliminating the need for third-party libraries like Apache HttpClient for many use cases. Below is a …
New Methods in String Class
Java 11 introduced six new methods to the String class to enhance string manipulation, particularly with better Unicode support and streamlined operations. Â isBlank() Purpose: Returns true if the string is empty or contains only whitespace characters (including Unicode whitespace), otherwise false. Use Case: Useful for validating input strings to check if they are effectively empty. …
Nest-Based Access Control
Nest-Based Access Control, introduced in Java 11 via JEP 181, is a mechanism that enhances how nested classes and interfaces interact within the Java programming language, specifically addressing access control for private members. Below is a concise explanation: What is Nest-Based Access Control? In Java, classes and interfaces can be nested within each other (e.g., …
ZGC: A Scalable Low-Latency Garbage Collector
ZGC (Z Garbage Collector) is a scalable, low-latency garbage collector introduced in Java 11 (JEP 333) and production-ready in Java 15. Designed for applications requiring minimal pause times and handling large heaps (multi-terabyte), ZGC achieves pause times typically under 10ms, regardless of heap size, making it ideal for latency-sensitive systems. It’s enabled with -XX:+UseZGC. Key …
Epsilon: A No-Op Garbage Collector
Epsilon is a no-op garbage collector in Java (introduced in JEP 318, Java 11) that allocates memory but does not reclaim it, leading to a JVM crash with an OutOfMemoryError when the heap is exhausted. It’s enabled with -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC. Below, I’ll explain Epsilon briefly and provide a sample use case with code to demonstrate …
Unicode 10 Support
Java 11, released in September 2018, includes support for Unicode 10.0.0, which was a significant update to the Unicode standard. Below is a concise overview of Unicode 10 support in Java 11 and its relevance as a feature: Unicode 10 Support in Java 11 Unicode Version: Java 11 supports Unicode 10.0.0, released in June 2017, …
Single-File Source-Code Programs
The Single-File Source-Code Programs feature, introduced in Java 11 via JEP 330, allows developers to execute a Java source file directly using the java launcher without explicitly compiling it first. This feature is particularly useful for beginners learning Java, writing small utility programs, or quickly testing code snippets. Important Points Purpose: Simplifies running single-file Java …
Local-Variable Syntax for Lambda Parameters
Introduced in Java 11 via JEP 323, this feature allows the var keyword (originally introduced for local variables in Java 10) to be used in lambda parameter declarations. It enables type inference for lambda parameters, reducing verbosity and aligning lambda syntax with local variable declarations. Syntax You can use var instead of explicit types in …