Java 11, released in September 2018, was the first Long-Term Support (LTS) version under Oracle’s new six-month release cadence. It was a "clean-up" release that removed legacy components (like JavaFX and Java EE modules) and introduced modern APIs designed for the cloud and container era.
While Java 10 introduced var for local variables, Java 11 extended this to Lambda expressions.
- The Enhancement: You can now use
varin the formal parameters of an implicitly typed lambda expression. - The "Why": Previously, if you wanted to apply an annotation (like
@Nonnull) to a lambda parameter, you had to write out the full manifest type. Now, you can usevarto keep it concise while still allowing annotations.
// Java 8/10: Must use full type for annotations
list.stream()
.map((@Nonnull String x) -> x.toLowerCase())
.collect(Collectors.toList());
// Java 11: Use var for conciseness with annotations
list.stream()
.map((@Nonnull var x) -> x.toLowerCase())
.collect(Collectors.toList());After being an "incubator" feature in Java 9 and 10, the new HTTP Client became a permanent standard in Java 11.
- The Enhancement: Replaces the ancient
HttpURLConnection. The new API supports HTTP/2 and WebSockets natively. - The "Why": The old API was difficult to use, synchronous, and didn't support modern web protocols efficiently. The new API is asynchronous (non-blocking) and uses a fluent builder pattern.
HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.example.com/data"))
.GET()
.build();
// Asynchronous call using CompletableFuture
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();This feature significantly improved the "on-ramping" experience for beginners and scripted automation.
- The Enhancement: You can run a Java source file directly with the
javacommand without manually compiling it withjavac. - The "Why": It makes Java feel more like a scripting language (like Python or Bash) for small utilities.
# Instead of:
# javac HelloWorld.java
# java HelloWorld
# You can simply run:
java HelloWorld.java
Java 11 added several "quality of life" methods to the most commonly used classes.
-
String Enhancements:
-
isBlank(): Returns true if the string is empty or contains only white space. -
lines(): Returns a stream of lines extracted from the string. -
repeat(n): Concatenates the string n times. -
strip(): A "Unicode-aware" version oftrim(). -
Files Enhancements:
-
Files.readString(path)/Files.writeString(path, string): Read or write entire files with a single method call.
String multiLine = "Line 1\nLine 2\nLine 3";
multiLine.lines().forEach(System.out::println);
String greeting = " Hello! ".strip().repeat(3);
// Output: "Hello!Hello!Hello!"
Path path = Path.of("test.txt");
String content = Files.readString(path); // No more BufferedReader boilerplate!Java 11 introduced the first version of ZGC (Z Garbage Collector).
- The Enhancement: A "no-pause" garbage collector designed for applications that require low latency (pauses less than 10ms) and very large heaps (terabytes).
- The Result: It performs all heavy lifting (marking, compacting) concurrently with the application threads.
Java 11 completed the "cleanup" started in Java 9.
- The Shift: Modules like JAXB, JAX-WS (Web Services), and CORBA were removed from the JDK.
- The Impact: If your application relies on these, you must now include them as external Maven/Gradle dependencies. This resulted in a much smaller and more secure JDK core.
| Feature | Category | Primary Benefit |
|---|---|---|
| HTTP Client | API | Modern, non-blocking networking. |
var in Lambdas |
Language | Conciseness with support for annotations. |
| Single-file Launch | Tooling | Faster development for scripts/prototypes. |
| String/File APIs | API | Massive reduction in boilerplate code. |
| ZGC (Intro) | Performance | Foundation for ultra-low latency GC. |
| Epsilon GC | Performance | A "no-op" GC for performance testing. |