Fundamentals 6 min read

New Features in Java 9–11: Local Variable Type Inference, HTTP Client, Collections, Streams, Optionals, and More

This article introduces the major Java 9‑11 language and API enhancements—including var type inference, the standardized HttpClient, immutable collection factories, new Stream methods, Optionals improvements, and additional VM features—providing concise code examples for engineers and architects.

High Availability Architecture
High Availability Architecture
High Availability Architecture
New Features in Java 9–11: Local Variable Type Inference, HTTP Client, Collections, Streams, Optionals, and More

Local Variable Type Inference

Java 10 introduced the var keyword, allowing the compiler to infer the type of local variables. The article shows the traditional String s = "text"; declaration and the equivalent var s = "text"; form, explains static typing, and demonstrates compile‑time errors when the inferred type is incompatible or cannot be determined.

HTTP Client

Starting with Java 9, the HttpClient API was added, and it became part of the standard library in Java 11 (package java.net ). The article illustrates synchronous and asynchronous requests, usage of BodyHandlers for different response types, and shows how to send POST data and perform BASIC‑AUTH.

Collections

Java 11 expands collection factories: List.of(...) creates immutable lists, List.copyOf(...) returns an immutable copy, and Map.of(...) builds immutable maps. The article explains that immutable collections share the same instance when the source is already immutable, while mutable copies produce new instances.

Streams

Java 9 adds three new Stream methods, including takeWhile and dropWhile , which allow selective element processing. The article provides examples of the new single‑argument constructor and demonstrates the new methods.

Optionals

Optionals now support conversion to streams and chaining with or to provide fallback values, simplifying null‑handling patterns.

Strings

Java 11 adds helper methods to String for trimming, checking blankness, and other common operations.

InputStreams

The transferTo method on InputStream enables direct transfer of data to an OutputStream .

Other JVM Features

The article lists additional Java 8‑11 enhancements such as the Flow API, Module System, Application Class‑Data Sharing, Dynamic Class‑File Constants, JShell, Flight Recorder, Unicode 10, G1, ZGC, Epsilon GC, and the deprecation of Nashorn.

JavaCollectionsStreamsnew featuresHTTP ClientJava 11Local Variable Type Inference
High Availability Architecture
Written by

High Availability Architecture

Official account for High Availability Architecture.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.