Can you tell me some new features that were introduced in Java 11?

Java 11 is a Long-Term Support (LTS) release that introduced several enhancements focused on performance, modern APIs, developer productivity, and JVM improvements. It added a new HTTP Client API, new garbage collectors, String utility methods, and various language enhancements that made Java applications more efficient and easier to develop.

Key Points: • Java 11 introduced a standardized HTTP Client API for modern HTTP communication. • New String methods simplified common string operations. • JVM performance improved with new garbage collectors such as ZGC and Epsilon GC. • Lambda expressions became more flexible with local-variable syntax support. • Java 11 is an LTS release widely adopted in enterprise applications.

Major Features Introduced in Java 11:

1. HTTP Client API

A new standardized HTTP Client API was added to replace the older HttpURLConnection API.

Benefits:

• Supports HTTP/1.1 and HTTP/2 • Supports synchronous and asynchronous requests • Cleaner and more modern API

Example:

HttpClient client = HttpClient.newHttpClient();

2. Local-Variable Syntax for Lambda Parameters

Java 11 allows the use of var in lambda parameters.

Example:

(var name) -> name.toUpperCase()

Benefits:

• Improved readability • Consistent syntax with local variables

3. New String Methods

Java 11 introduced several useful String utility methods.

isBlank()

Checks whether a string contains only whitespace.

Example:

"   ".isBlank();

strip()

Removes leading and trailing Unicode whitespace.

Example:

" Java ".strip();

stripLeading()

Removes whitespace from the beginning.

Example:

" Java".stripLeading();

stripTrailing()

Removes whitespace from the end.

Example:

"Java ".stripTrailing();

repeat()

Repeats a string multiple times.

Example:

"Java".repeat(3);

Output:

JavaJavaJava

4. Files Utility Enhancements

A new method was introduced to read file content directly into a String.

Example:

String content = Files.readString(path);

Benefits:

• Less boilerplate code • Simpler file reading

5. Epsilon Garbage Collector

A no-op garbage collector that does not reclaim memory.

Benefits:

• Useful for performance testing • Helpful for benchmarking JVM behavior

6. Z Garbage Collector (ZGC)

A scalable, low-latency garbage collector designed for large heap sizes.

Benefits:

• Very short pause times • Suitable for high-performance applications

7. Running Single-File Java Programs

Java source files can be executed directly without explicit compilation.

Example:

java Hello.java

Benefits:

• Faster testing • Easier scripting

Example: Using one of the new String methods introduced in Java 11.

Code Example:

public class Demo {

    public static void main(String[] args) {

        String text = "Java ";

        System.out.println(text.repeat(3));
    }
}

Output:

Java Java Java

Benefits of Java 11 Features:

• Modern HTTP communication • Improved JVM performance • Better garbage collection options • Cleaner String handling • Simplified file operations • Improved developer productivity

Interview Tip: A concise interview answer is:

"Some important features introduced in Java 11 include the new HTTP Client API, Local-Variable Syntax for Lambda Parameters, Epsilon Garbage Collector, Z Garbage Collector, Single-File Source-Code Execution, Files.readString(), and new String methods such as isBlank(), strip(), stripLeading(), stripTrailing(), and repeat(). Java 11 is also a Long-Term Support (LTS) release widely used in enterprise applications."