Java 11 Features
Java 11 is the second Long-Term Support release after Java 8, and it arrived with a number of focused improvements that make everyday coding cleaner. Sever...
New String and Collection Utility Methods
Java 11 is the second Long-Term Support release after Java 8, and it arrived with a number of focused improvements that make everyday coding cleaner. Several new String methods stand out immediately because strings are central to almost every Java program.
String.isBlank() returns true if the string is empty or contains only whitespace, making it more expressive than the older str.trim().isEmpty() idiom. String.strip() trims whitespace using Unicode-aware rules, unlike the classic trim() which only handles ASCII whitespace characters below code point 32. stripLeading() and stripTrailing() trim only one side. String.repeat(int) creates a new string by repeating the original a given number of times — useful for formatting, padding, or generating test data. String.lines() returns a Stream<String> of lines split by line terminators, making multi-line text processing straightforward without manual splitting.
The var keyword for local variable type inference, introduced in Java 10, was extended in Java 11 to work in lambda parameter lists. This allows you to annotate lambda parameters — (var x, var y) -> x + y — which matters primarily when you want to apply an annotation to a parameter: (@NonNull var user) -> user.getId(). Without var, annotating an inferred lambda parameter was not possible.
Java 11 made running a single-file Java program much easier. You can now execute java HelloWorld.java directly without a separate javac compilation step. The JVM compiles the file in memory and runs it. This lowers the barrier for quick experiments, scripting, and educational examples significantly.
HTTP Client, incubated in Java 9 and finalized in Java 11, replaces the ancient HttpURLConnection API. The new java.net.http.HttpClient supports HTTP/1.1 and HTTP/2, asynchronous requests via CompletableFuture, and WebSockets. A synchronous GET is concise: HttpClient.newHttpClient().send(HttpRequest.newBuilder(URI.create(url)).build(), BodyHandlers.ofString()).body(). The fluent builder API is clear and the class is thread-safe by design.
HTTP Client, File and Optional Improvements
The finalized HttpClient in Java 11 deserves deeper exploration because it modernizes a long-neglected area of the standard library. Unlike HttpURLConnection, which was designed around blocking I/O and HTTP/1.1, the new client was built from the start to handle asynchronous workflows and HTTP/2 multiplexing.
Creating a client is done once and the instance is reused: HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).followRedirects(Redirect.NORMAL).build(). Sending an asynchronous request returns a CompletableFuture<HttpResponse<T>>, enabling non-blocking pipelines: client.sendAsync(request, BodyHandlers.ofString()).thenApply(HttpResponse::body).thenAccept(System.out::println). Multiple requests can run concurrently without threads you manage yourself.
Request bodies use BodyPublishers. Sending JSON: HttpRequest.BodyPublishers.ofString("{\"key\":\"value\"}"). Uploading a file: HttpRequest.BodyPublishers.ofFile(Path.of("data.csv")). Response bodies use BodyHandlers symmetrically: BodyHandlers.ofFile(Path.of("output.json")) streams the response directly to disk, which is important when downloading large files to avoid loading them into memory.
Java 11 added several methods to Optional. isEmpty() is the logical complement of isPresent(), making negative checks read naturally. ifPresentOrElse(consumer, runnable) handles both the present and absent cases in one call instead of requiring a conditional block. Optional.or(Supplier<Optional<T>>) chains fallback optional-producing logic: find the cached value, or else query the database, or else return empty.
Files gained two convenient methods. Files.readString(path) and Files.writeString(path, content) replace the verbose Files.readAllBytes or BufferedReader dance for small text files. Both handle character encoding correctly and accept a StandardCharsets parameter. These are not replacements for streaming APIs when working with large files, but they eliminate boilerplate in the common case of reading a configuration file or writing a small report.
Removed Features, GC Improvements, and Migration Notes
Understanding what Java 11 removed is as important as knowing what it added, especially if you are migrating a Java 8 codebase. The most disruptive removal is the Java EE and CORBA modules. Packages like javax.xml.bind (JAXB), javax.activation, javax.xml.ws (JAX-WS), and related APIs were removed from the JDK entirely. Code that uses JAXB for XML marshalling must now declare an explicit dependency — com.sun.xml.bind:jaxb-impl or jakarta.xml.bind:jakarta.xml.bind-api — in pom.xml or build.gradle.
The JavaFX UI toolkit was also separated from the JDK in Java 11. It now ships as an independent open-source project at openjfx.io and must be added as a dependency if your application uses it. Applications built on Swing or AWT are unaffected.
On the garbage collection side, Java 11 introduced two experimental collectors: Epsilon and ZGC. Epsilon is a no-op GC — it allocates memory but never reclaims it. This sounds useless but is valuable for performance testing (eliminates GC pauses from benchmarks) and short-lived programs where GC cost exceeds its benefit. ZGC is a scalable low-latency collector targeting pause times under 10ms even on multi-terabyte heaps. Both were experimental in Java 11 and improved substantially in later releases.
The module system from Java 9 became more relevant in Java 11 migrations. While you are not required to modularize your application, the JDK itself is modular, and the removal of internal APIs (like sun.misc.Unsafe in many use cases) can break libraries that reflected on private JDK internals. The jdeps tool, shipped with the JDK, scans your JAR for dependencies on removed or encapsulated APIs and generates a report you can act on before upgrading.
A migration tip: run your full test suite under Java 11 with --illegal-access=warn first. This surfaces reflective-access warnings without crashing the application, giving you a prioritized list of libraries to update before the stricter enforcement in later Java versions.