Java Reference ยท Language Features by Version
Java 9 to 11 features
What Java 9, 10 and 11 added: modules, collection factory methods, private interface methods, var, Optional and String additions, the HTTP client and single-file launch.
Between Java 9 (September 2017) and Java 11 (September 2018, LTS) the platform moved to its six-month release train. These three releases mostly polished Java 8: convenient factory methods for collections, var for local variables, many small additions to String, Optional and streams, a modern HTTP client and the ability to run a single source file directly with java Main.java.
Java 9 also introduced the module system (JPMS), the largest internal change, and removed a number of Java EE and CORBA modules (finally in Java 11), which broke some old applications.
var names = List.of("ann", "bob"); // var: Java 10, List.of: Java 9
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.
Feature list
| Version | Language | Library and platform |
|---|---|---|
| Java 9 | Modules (module-info.java), private methods in interfaces, effectively final variables in try-with-resources, diamond with anonymous classes. |
List.of/Set.of/Map.of, Stream.takeWhile/dropWhile/iterate with predicate, Optional.or/ifPresentOrElse/stream, ProcessHandle, Flow API, StackWalker, compact strings, G1 as the default collector, JShell, jlink. |
| Java 10 | var for local variables. |
List.copyOf, toUnmodifiableList, Optional.orElseThrow(), container awareness in the JVM, parallel full GC for G1. |
| Java 11 (LTS) | var in lambda parameters. |
Standard HttpClient, String.isBlank/strip/repeat/lines, Files.readString/writeString, java Main.java single-file launch, Collection.toArray(IntFunction), Predicate.not, Epsilon and ZGC (experimental), TLS 1.3. Removed: Java EE and CORBA modules, Java Web Start. |
Usage notes
varis not dynamic typing. The compiler infers one static type from the initializer. It works only for local variables,forvariables and lambda parameters, not for fields, method parameters or return types.- Immutable factories reject
nullandList.ofthrowsNullPointerExceptionfromcontains(null)too.Set.ofandMap.ofthrow on duplicate elements or keys, and their iteration order is deliberately unspecified. - Modules are optional. A classpath application keeps working, but internals such as
sun.misc.Unsafeand reflection into JDK classes are restricted (--add-opensflags as a workaround). See modules. - Source-file mode (Java 11).
java Main.javacompiles in memory and runs. It is a single file and has no classpath tricks, which is exactly what this site uses. - HttpClient is the replacement for
HttpURLConnection; seeHttpClient. - Removed in Java 11:
javax.xml.bind(JAXB),javax.activation,javax.annotation,java.corba,java.transaction. Add them as Maven dependencies when migrating from Java 8. - Oracle JDK and OpenJDK builds became interchangeable at Java 11; paid support rules differ by vendor.
- Java 9 and 10 are not LTS and no longer receive updates. Projects migrating from 8 usually jump to 11, 17 or newer.
Related
- Java 8 features, Java 12 to 17,
var,List.of(),Map.of(), JShell - Lessons: var, Modules, HTTP client