JEP
JSR 376: Java Platform Module System (opens in a new tab)
Compile and run code with JPMS CLI options
-
--add-exportsto export a package, which makes its public types and members accessible (javac and java) -
--add-opensto open a package, which makes all its types and members accessible (java) -
--patch-moduleadds classes to a specific module -
--add-modulesadds the listed modules and their transitive dependencies to the module graph -
--add-readsmakes one module read another -
Five Command Line Options To Hack The Java Module System (opens in a new tab)
Create custom JRE image
jlink --add-modules java.base,java.logging[,modules...] --output $output_dirList module dependencies of the specified Java JAR/class
jdeps -s $jar_fileExample:
❯ jdeps -s target/ms.jar
ms.jar -> java.base
ms.jar -> java.sql
ms.jar -> jdk.jfror
jdeps -s $java_classExample:
❯ jdeps -s MetricResponse.class
MetricResponse.class -> java.baseJEP 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 toifPresent, but if there is no value, it executes theemptyAction.or(Supplier supplier): This method is useful when you want to ensure that you always have anOptional. Theor()method returns the sameOptionalif a value is present; otherwise, it returns a newOptionalj 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
--releaseoption in place of--sourceand--targetoptions