Java 11, released on September 25, 2018, was a major milestone in the Java ecosystem. It was the first Long-Term Support (LTS) release under the new six-month release cycle, marking a shift toward more rapid innovation while providing stability for enterprise applications.
This release focused on modernising the platform, cleaning up deprecated APIs (like Java EE modules), and adding powerful new features that reduce boilerplate and improve performance. Let’s explore the key features that defined Java 11.
Key Features
Standard HTTP Client API
Introduced as an incubator in Java 9, the HTTP Client API became standard in Java 11. It replaces the legacy
HttpURLConnectionwith a modern, non-blocking, and asynchronous API that supports HTTP/1.1 and HTTP/2.
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.example.com/data"))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println);
Benefits:
- Native support for HTTP/2 and WebSockets
- Non-blocking asynchronous requests
- Better performance and cleaner API than legacy alternatives
Built-in support for streaming and reactive streams
String & Files API Enhancements
Java 11 added several utility methods to
StringandFilesclasses that eliminate common boilerplate code for checking empty strings, repeating text, and reading/writing files.
// String enhancements
String text = " Java 11 ";
System.out.println(text.isBlank()); // false
System.out.println(text.strip()); // "Java 11"
System.out.println("Hi ".repeat(3)); // "Hi Hi Hi "
// Files enhancements
Path path = Path.of("example.txt");
Files.writeString(path, "Hello Java 11");
String content = Files.readString(path);
Benefits:
- Cleaner code for common string manipulations
- Simplified file I/O for small text files
- Better Unicode support with
strip()vstrim() Massive reduction in code for simple tasks
Local-Variable Syntax for Lambda Parameters
Building on the
varkeyword introduced in Java 10, Java 11 allows usingvarfor formal parameters of implicitly typed lambda expressions. This is particularly useful when you need to apply annotations to lambda parameters.
// Before Java 11: Needs full type for annotations
( @NotNull String s1, @NotNull String s2) -> s1 + s2
// Java 11: Use var with annotations
( @NotNull var s1, @NotNull var s2) -> s1 + s2
Benefits:
- Consistency with local variable type inference
- Enables annotations on lambda parameters without needing explicit type names
Maintains readability while allowing meta-programming
Predicate::not and More Enhancements
Java 11 introduced small but high-impact improvements like the
notpredicate, a simpler way to convert collections to arrays, and the ability to run single-file source code programs directly.
// Predicate.not()
List<String> result = list.stream()
.filter(Predicate.not(String::isBlank))
.collect(Collectors.toList());
// Collection to Array
String[] array = list.toArray(String[]::new);
// Single-file execution
// > java HelloWorld.java
Benefits:
- More readable functional pipelines with
Predicate.not() - Elegant collection-to-array conversion
- Faster prototyping with direct source file execution
- Improved security with Nest-Based Access Control
Why Upgrade to Java 11?
Foundation for Modern Java
Java 11 is the baseline for many modern frameworks and libraries. Moving to Java 11 opens the door to using the latest versions of Spring, Quarkus, and Micronaut.
Performance and Efficiency
With improvements like G1 GC as the default and the introduction of Epsilon (No-Op GC) and ZGC (Experimental in 11), Java 11 is more efficient in memory management and containerised environments.
LTS Stability
As an LTS release, Java 11 provides the long-term stability needed for enterprise-grade applications, with years of security updates and community support.
Conclusion
Java 11 was more than just a new version; it was a modernization effort that prepared Java for the future. From the modern HTTP Client to small but powerful String utilities and Local-Variable syntax for lambdas, it made the language more expressive and developer-friendly.
If you are looking to build stable, high-performance applications with modern tooling, Java 11 remains a fantastic starting point. While Java 17 and Java 21 have since introduced even more power, Java 11 set the stage for this exciting new era of Java.