Skip to content
AstralSurgeLearnings XP 0 Streak 0
AstralSurgeLearnings

Java 11 - Overview

Released in September 2018, Java 11 marked a major milestone in the Java ecosystem as the first Long-Term Support (LTS) release under the rapid six-month release cadence. Java 11 introduced essential developer productivity enhancements, standardized modern web capabilities, and streamlined the JDK runtime by shedding legacy components.

Key Language and API Additions

1. New Utility Methods in java.lang.String

Java 11 eliminated frequent boilerplate code by introducing several highly requested string helper methods:

  • isBlank(): Returns true if a string is empty or contains only white space.
  • lines(): Returns a lazy stream of lines extracted from the string, handling all newline variants (\n, \r\n).
  • strip(), stripLeading(), stripTrailing(): Unicode-aware alternatives to trim() that accurately recognize and remove leading and trailing whitespace.
  • repeat(int count): Returns a new string with the original value repeated the specified number of times.
String text = "  AstralSurge  \n  Learnings  ";
System.out.println("   ".isBlank());       // true
System.out.println(text.strip());           // "AstralSurge  \n  Learnings"
System.out.println("Java ".repeat(3));      // "Java Java Java "

// Stream lines
text.lines().map(String::strip).forEach(System.out::println);

2. Simplified File I/O Methods

The java.nio.file.Files class added static utility methods to read and write entire string payloads without managing custom buffered readers or output streams:

Path filePath = Path.of("sample.txt");

// Write string to file
Files.writeString(filePath, "Modern Java 11 I/O");

// Read file contents directly into a String
String content = Files.readString(filePath);
System.out.println(content); // Modern Java 11 I/O

3. Standardized HTTP Client (JEP 321)

Replacing the dated HttpURLConnection, Java 11 promoted the modern, non-blocking HTTP Client to the standard library under java.net.http. It natively supports HTTP/1.1, HTTP/2, WebSockets, and asynchronous non-blocking pipelines using CompletableFuture:

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.github.com"))
        .GET()
        .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status: " + response.statusCode());

4. Local-Variable Syntax for Lambda Parameters (JEP 323)

Java 11 allows using var inside lambda parameter declarations to apply annotations (such as @NotNull) to inferred parameters without losing succinctness:

List<String> items = List.of("apple", "banana", "cherry");
items.stream()
     .map((@NonNull var s) -> s.toUpperCase())
     .forEach(System.out::println);

5. Launch Single-File Source-Code Programs (JEP 330)

Developers can execute single-file Java source files directly without an explicit javac compilation step. Running java App.java compiles the program in-memory and launches the main method directly, significantly streamlining scripting and quick prototyping.

JVM, Security, and Garbage Collection Updates

  • Epsilon GC (JEP 318): A no-op garbage collector designed for performance testing and short-lived batch jobs that terminates once allocated heap memory is exhausted.
  • ZGC Experimental Preview (JEP 333): A scalable low-latency garbage collector capable of handling multi-terabyte heaps with pause times below 10 milliseconds.
  • Transport Layer Security (TLS) 1.3 (JEP 332): Provided out-of-the-box support for the cryptographic improvements and reduced handshake latency of TLS 1.3.

Cleanups and Deprecations

Java 11 aggressively pruned legacy enterprise components to make the runtime modular and lightweight:

  • Removal of Java EE and CORBA Modules (JEP 320): Deprecated since Java 9, modules such as JAXB, JAX-WS, and CORBA were completely removed from the standard JDK. Applications requiring them must include external dependencies (e.g., jakarta.xml.bind).
  • Removal of JavaFX and Applet Viewer: JavaFX was decoupled from the JDK and made available as a standalone modular library (OpenJFX).
  • Deprecation of Nashorn JavaScript Engine (JEP 335): Marked for removal due to rapid ECMAScript specification evolution.

0 Comments