Skip to content
Tutorials Center
My learning

Topics

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.

Java
var names = List.of("ann", "bob");   // var: Java 10, List.of: Java 9

Try it

Java Java 9: factory methods, private interface methods, Stream and Optional additions

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.

Java Java 10 and 11: var, copyOf and lambda parameters

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.

Java Java 11 String additions and Files helpers

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

  • var is not dynamic typing. The compiler infers one static type from the initializer. It works only for local variables, for variables and lambda parameters, not for fields, method parameters or return types.
  • Immutable factories reject null and List.of throws NullPointerException from contains(null) too. Set.of and Map.of throw 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.Unsafe and reflection into JDK classes are restricted (--add-opens flags as a workaround). See modules.
  • Source-file mode (Java 11). java Main.java compiles 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; see HttpClient.
  • 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.