Java 9

JEP

JSR 376: Java Platform Module System (opens in a new tab)

Compile and run code with JPMS CLI options

  • --add-exports to export a package, which makes its public types and members accessible (javac and java)

  • --add-opens to open a package, which makes all its types and members accessible (java)

  • --patch-module adds classes to a specific module

  • --add-modules adds the listed modules and their transitive dependencies to the module graph

  • --add-reads makes one module read another

  • Five Command Line Options To Hack The Java Module System (opens in a new tab)

Create custom JRE image

List module dependencies of the specified Java JAR/class

  • jdeps -s <path/JAR file/class file>

JEP 269: Convenience Factory Methods for Collections (opens in a new tab)

  • Before
List<Point> myList = new ArrayList<>);
myList.add(new Point(1, 1));
myList.add(new Point(2, 2));
myList.add(new Point(3, 3));
myList.add(new Point(4, 4));
myList = Collections.unmodifiableList(myList);
  • Now
List<Point> list = List.of(new Point(1, 1), new Point(2, 2), new Point(3, 3), new Point(4, 4));

Optional Class Enhancements

  • ifPresent(Consumer action): If there is a value present, perform the action using the value.
  • ifPresentOrElse(Consumer action, Runnable emptyAction): Similar to ifPresent, but if there is no value, it executes the emptyAction.
  • or(Supplier supplier): This method is useful when you want to ensure that you always have an Optional. The or() method returns the same Optional if a value is present; otherwise, it returns a new Optionalj created by the supplier.
  • stream(): Returns a stream of zero or one elements, depending on whether there is a value.

Stream API Enhancements

JEP 264: Platform Logging API and Service (opens in a new tab)

JEP 266: More Concurrency Updates (opens in a new tab)

JEP 102: Process API Updates (opens in a new tab)

JEP 222: jshell: The Java Shell (Read-Eval-Print Loop) (opens in a new tab)

JEP 247: Compile for Older Platform Versions (opens in a new tab)

  • Use --release option in place of --source and --target options

JEP 248: Make G1 the Default Garbage Collector (opens in a new tab)

References