1. Introduction
Java 11, released as a Long-Term Support (LTS) version in September 2018, brought several important improvements that modernize the platform, simplify code, and improve runtime performance. It is defined by the official platform specification: JSR 384 – Java SE 11 Platform Specification. In this article, we’ll explore five key features introduced in JDK 11 that every Java developer should know.
⚠️ Note: JDK 11 removes several deprecated APIs and modules. Be sure to test legacy code for compatibility before upgrading.
2. Local-Variable Syntax for Lambda Parameters (JEP 323)
JEP 323 allows the use of var
in lambda parameter declarations, enabling type annotations for lambda parameters without sacrificing conciseness.
var list = List.of("Java", "11", "LTS");
list.forEach((var item) -> System.out.println(item.toUpperCase()));
Why it matters: Enables cleaner code and allows annotations like @Nonnull
on lambda parameters.
3. HTTP Client Standardized (JEP 321)
JEP 321 standardizes the HTTP Client API introduced as an incubator in JDK 9. It supports HTTP/1.1, HTTP/2, and WebSocket.
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://example.com"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
Why it matters: Provides a modern, non-blocking HTTP client in the core JDK.
4. String Methods Enhancements
JDK 11 adds new utility methods to String
, including isBlank()
, lines()
, strip()
, and repeat(int)
.
These enhancements were introduced as part of the standard Java API update and were not covered by a specific JEP.
System.out.println(" Hello ".strip());
System.out.println("Java\n11\nRocks".lines().count());
System.out.println("Hi! ".repeat(3));
System.out.println(" ".isBlank());
Why it matters: Reduces the need for external libraries or verbose utility code.
5. Files.readString()
and writeString()
(JEP 330)
JEP 330 introduced simplified methods to read and write files using String
.
Path file = Path.of("example.txt");
Files.writeString(file, "Java 11 is productive!");
String content = Files.readString(file);
System.out.println(content);
Why it matters: Makes file I/O easier and more intuitive.
6. Running Java Files Without Compilation (JEP 330)
JEP 330 allows executing a Java file directly using the java
launcher without explicitly compiling it.
java HelloWorld.java
Why it matters: Great for scripting, quick demos, or learning — no manual compilation needed.
7. Conclusion
Java 11 focused on improving developer productivity, standardizing core APIs, and simplifying code. These features continue to make Java a robust and modern programming language. Whether you’re migrating from Java 8 or starting fresh, understanding these key additions will help you write cleaner, faster, and more expressive Java code.
You can find the complete code of this article here in GitHub.