Java 11 is an LTS release and remains a common production baseline. This guide covers the important Java 11 additions with practical examples.
1) New String Methods
Java 11 adds useful String APIs: isBlank(), strip(), stripLeading(), stripTrailing(), repeat(), and lines().
String raw = " hello\t";
System.out.println(raw.isBlank()); // false
System.out.println(raw.strip()); // "hello"
System.out.println("ha".repeat(3)); // "hahaha"
"a\nb\nc".lines().forEach(System.out::println); // a b c
2) Files API Convenience Methods
Files.readString() and Files.writeString() reduce boilerplate.
Path path = Path.of("notes.txt");
Files.writeString(path, "Java 11 is clean.\n");
String data = Files.readString(path);
System.out.println(data);
3) HTTP Client (Standard API)
The incubating HTTP client became standard in Java 11 (java.net.http), supporting HTTP/1.1, HTTP/2, sync and async calls.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
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(response.statusCode());
System.out.println(response.body().substring(0, 80));
Async:
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
4) Local-Variable Syntax (var) in Lambda Parameters
Java 11 allows var in lambda parameters, useful when adding annotations.
import java.util.List;
List<String> names = List.of("Alice", "Bob");
names.forEach((var name) -> System.out.println(name.toUpperCase()));
With annotations:
// Example shape:
// ( @Nonnull var value ) -> value.trim()
Rule: if one lambda parameter uses var, all must use var.
5) Optional.isEmpty()
Cleaner inverse of isPresent().
Optional<String> token = Optional.empty();
if (token.isEmpty()) {
System.out.println("Missing token");
}
6) Predicate.not(...)
Improves readability in stream filters.
import java.util.List;
import java.util.function.Predicate;
List<String> values = List.of("java", "", "jdk11", "");
List<String> nonBlank = values.stream()
.filter(Predicate.not(String::isBlank))
.toList();
System.out.println(nonBlank); // [java, jdk11]
7) Running Single-File Source Code
You can run one-file programs directly without explicit compilation.
Hello.java:
public class Hello {
public static void main(String[] args) {
System.out.println("Run with: java Hello.java");
}
}
Command:
java Hello.java
8) Nest-Based Access Control (JVM)
Nested classes can access each other’s private members through JVM nestmates, reducing synthetic bridge methods.
class Outer {
private int secret = 42;
class Inner {
int read() {
return secret; // direct nestmate access
}
}
}
This mainly improves generated bytecode and runtime access checks.
9) Dynamic Class-File Constants (JVM)
Java 11 introduces dynamic constants (CONSTANT_Dynamic) in class files.
This is mostly relevant for bytecode tools and runtime language frameworks.
Use case examples:
- optimized constant bootstrapping in generated bytecode
- reduced class initialization overhead in some dynamic frameworks
10) Java Flight Recorder (JFR) Available in OpenJDK
JFR is available for production diagnostics with low overhead.
Start recording at JVM startup:
java -XX:StartFlightRecording=filename=app.jfr,duration=60s -jar app.jar
Useful for:
- allocation hotspots
- GC pauses
- thread contention and lock profiling
11) New Garbage Collectors in Java 11
Epsilon GC (No-Op GC)
Useful for performance testing where you want no GC work:
java -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC App
ZGC (Experimental in Java 11)
Designed for very low pause times on large heaps:
java -XX:+UnlockExperimentalVMOptions -XX:+UseZGC App
Note: ZGC matured in later Java releases; in Java 11 it is experimental.
12) Security and Crypto Updates
Java 11 includes important security upgrades:
- TLS 1.3 support
- ChaCha20 and Poly1305 cryptographic algorithms
- Curve25519 and Curve448 key agreement support
These improvements strengthen modern HTTPS and secure service-to-service communication.
13) Removed / Changed in Java 11
Important migration notes:
- Java EE and CORBA modules removed from JDK
- deployment stack removed (
appletviewer, Java Web Start components) - Nashorn JavaScript engine deprecated (removed later)
If migrating from Java 8, check module dependencies before upgrading.
Migration Checklist (Java 8 -> 11)
- replace
HttpURLConnectionheavy usage withHttpClientwhere suitable - update string/file utility code to new APIs
- validate removed Java EE/CORBA module usage
- run load tests with your selected GC (
G1,ZGCin later LTS, etc.) - enable JFR in staging and production for profiling
Practical Adoption Order
When upgrading teams/codebases, introduce features in this order:
- low-risk API wins (
isBlank,readString,writeString,Optional.isEmpty) HttpClientfor new integrations- observability upgrades (JFR operational playbooks)
- GC/runtime tuning after baseline metrics
This keeps migration incremental and easier to validate.
Common Upgrade Pitfalls
- assuming old Java EE classes still ship with JDK 11
- switching HTTP stack without timeout/retry parity checks
- enabling experimental GC flags in production without benchmarking
- missing TLS/cipher compatibility tests with legacy downstream services
Treat JDK upgrade like a platform migration, not just syntax refresh.
Verification Checklist in CI/CD
- run unit/integration tests on JDK 11 runtime
- run dependency scan for removed modules
- execute smoke tests for external HTTP and TLS connectivity
- capture baseline JFR profile before and after upgrade
These checks catch most migration surprises early.
Key Takeaways
- Java 11 adds practical API improvements (
String,Files,Optional,HttpClient). - It also includes significant JVM/runtime upgrades (JFR, nestmates, new GC options).
- As an LTS release, Java 11 is a strong baseline for enterprise backend systems.