What did Java 11 bring over Java 8 that a working Java developer actually uses?
answer
- three releases in one jump
- unmodifiable collections in one call
- local type inference, not dynamic typing
- a standard way to call HTTP
- the modules that left the JDK
basics
~20 sJava 11 collects Java 9, 10 and 11: the module system, List.of and friends, var, the standard HTTP client, and new String and Files helpers. It also removed the Java EE and CORBA modules, so Java EE code needs separate dependencies.
solid answer
~40 sGoing from 8 to 11 takes in three releases. In daily code I use `List.of`, `Set.of` and `Map.of` for unmodifiable collections, `var` for local variables, `Stream.takeWhile`, `Optional.ifPresentOrElse`, the `String` helpers such as `isBlank` and `strip`, `Files.readString`, and the standard `java.net.http` client. At runtime, G1 became the default collector on server configurations, compact strings cut the memory used by Latin-1 text, and Flight Recorder became generally available for low-overhead diagnostics. The migration work is the other half: the module system encapsulated most internal APIs, though class-path code could still reach those from JDK 8 at run time, with one warning, and Java 11 removed the Java EE and CORBA modules, so `javax.xml.bind` needs a separate dependency.
code
java · 23 linesimport java.io.IOException;
import java.nio.file.Files;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class Java11Idioms {
public static void main(String[] args) throws IOException {
var file = Files.createTempFile("demo", ".txt"); // var: Java 10
Files.writeString(file, "alpha\n\n beta \n"); // Java 11
var words = Files.readString(file).lines() // both Java 11
.map(String::strip) // Java 11
.filter(Predicate.not(String::isBlank)) // both Java 11
.collect(Collectors.toUnmodifiableList()); // Java 10
var limits = Map.of("alpha", 1, "beta", 2); // Java 9
System.out.println(words);
System.out.println(limits.get(words.get(1)));
Files.delete(file);
}
}go deeper
Recall the everyday additions: List.of, var, the new String helpers and Files.readString. Know which release each one came from if you can, and do not attribute them to Java 8.
Explain the migration mechanics: internal APIs encapsulated at compile time, the permissive illegal-access default at run time, and the removal of the Java EE modules at 11 with no flag to restore them.
Describe an upgrade you have run: finding internal API use with jdeps, replacing removed modules with dependencies, checking the collector change and reading the warnings before they become failures.
Frame the jump as a platform decision: whether to modularize at all, how to move many services together, and why a thin class-path upgrade first usually carries less risk than combining it with modularization.
## Three releases, one upgrade Moving from Java 8 to Java 11 means taking three feature releases at once: Java 9 (September 2017), Java 10 (March 2018) and Java 11 (September 2018). The honest answer to this question covers two things: what you start writing, and what stops working. Candidates who list only the first have often not done the upgrade. ## What you use in daily code | Added | Release | What it does | |---|---|---| | `List.of`, `Set.of`, `Map.of` | 9 | Compact, unmodifiable collections that reject `null` elements | | `Stream.takeWhile`, `dropWhile` | 9 | Cut a stream at the first element that fails a predicate | | `Optional.ifPresentOrElse`, `Optional.stream` | 9 | Handle both outcomes, or feed an `Optional` into a pipeline | | Private interface methods | 9 | Share code between default methods | | `var` | 10 | Infers the type of a local variable from its initializer | | `List.copyOf`, `Collectors.toUnmodifiableList` | 10 | Unmodifiable snapshots of existing data | | `Optional.orElseThrow()` | 10 | A clearer name for `get()` | | `String.isBlank`, `strip`, `lines`, `repeat` | 11 | Text helpers, covered in depth with the new String methods | | `Files.readString`, `Files.writeString`, `Path.of` | 11 | One-line file reads and writes | | `Predicate.not`, `Optional.isEmpty` | 11 | Small readability helpers | | `java.net.http.HttpClient` | 11 | The standard HTTP client, after incubating from Java 9 | `var` is still static typing: the compiler infers the type once, and it never changes. It works on local variables with initializers and on loop variables, and Java 11 also allows it on implicitly typed lambda parameters. It does not work on fields, method parameters, return types or catch parameters. Two tools also make small experiments cheaper: `jshell` (Java 9) and launching a single source file with the `java` command (Java 11). Each has its own question; here it is enough to name them. ## What changed at runtime - **G1 became the default collector** on server configurations in Java 9 (JEP 248), replacing the throughput-oriented Parallel collector as the default. - **Compact strings** (JEP 254, Java 9): a string holding only Latin-1 characters uses one byte per character, with no code change. - **Application class-data sharing** (JEP 310, Java 10) extends class-data sharing to application classes, which helps startup. - **Flight Recorder** (JEP 328, Java 11) gives a low-overhead data collection framework for troubleshooting applications and the JVM. It had existed for years as a commercial feature, and this JEP moved it to the open repository. - **TLS 1.3** (JEP 332, Java 11): the JDK implements the new protocol version, though not every feature of it. - **ZGC and Epsilon** arrived at Java 11 as well, both as experimental collectors. ZGC became a production feature in Java 15. ## What can break This is the part an interviewer probes: - **Encapsulation.** The module system (JEP 261) and JEP 260 make most internal JDK APIs inaccessible at compile time. At run time, the default `--illegal-access=permit` still let class-path code reach those in packages that existed in JDK 8, with one warning on the first reflective access. That default lasted until Java 16. - **Removed modules.** JEP 320 removed nine modules at Java 11, including `java.xml.bind`, `java.xml.ws`, `java.activation`, `java.transaction` and `java.corba`. On Java 9, `--add-modules` could still enable them. At 11 no flag can, so code using the Java EE APIs needs standalone versions as dependencies. JEP 320 says there will be no standalone CORBA unless third parties take it over. - **Deprecations to plan for.** Java 11 deprecated the Nashorn engine (JEP 335) and the Pack200 tools (JEP 336). Both were removed later. - **Finding the exposure.** `jdeps --jdk-internals` lists a JAR's dependencies on internal JDK APIs, so you can size the work before you start. You do **not** have to modularize. Code on the class path runs in the unnamed module, so an application can upgrade to Java 11 without writing a `module-info.java`. `jlink` (JEP 282) and multi-release JARs (JEP 238) are there if you want them, and neither is required. ## How to answer Name three or four things you use, then say what you had to fix. A sentence such as "we added explicit XML-binding dependencies and cleaned up internal API use before moving" tells an interviewer more than a complete list of JEPs would.
- Do you need a module-info.java to run an application on Java 11?No. Code on the class path belongs to the unnamed module, which can read every other module, so a class-path application runs without any module declaration. Modularizing is a separate choice. What you cannot avoid is the encapsulation of JDK internals and the removal of the Java EE modules.
- Code using javax.xml.bind compiled on Java 8 and fails on Java 11. What are your options?JEP 320 removed the `java.xml.bind` module, and no flag brings it back at 11, although `--add-modules java.xml.bind` helped on Java 9. The fix is to add a standalone version of the API and its implementation as ordinary dependencies, or to move off the API.
- When would you avoid var even though it compiles?When the initializer does not show the type, such as `var result = service.process(input)`, because the reader now has to look up the method. It also pins the variable to the concrete type: `var list = new ArrayList<String>()` is an `ArrayList`, not a `List`. Use it where the type is obvious from the right-hand side.
- Moving to Java 11 means rewriting the application as modules.
- List.of returns an ordinary mutable list, just like new ArrayList.
- var makes Java dynamically typed.
- JAXB is still in the JDK at Java 11, only deprecated.
- --add-modules java.xml.bind brings the removed module back on Java 11.
- The java.net.http client is still an incubator module at Java 11.
- Module system
- Java 9
- Collection factory methods such as List.of
- Java 9
- Local-variable type inference (var)
- Java 10
- Standard HTTP Client (java.net.http)
- Java 11pre-release 9
- JAXB in the JDK (java.xml.bind)
- Java 1.6removed 11
Assumes JDK 27 as the baseline and describes the jump from Java 8 to 11; illegal-access behaviour differs later, since that option became obsolete at Java 17.
context
- JDK 9openjdk.org
- JDK 11openjdk.org
- JEP 320: Remove the Java EE and CORBA Modulesopenjdk.org