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
-
jlink --add-modules java.base,java.logging[,modules...] --output <output-directory>
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 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 sameOptional
if a value is present; otherwise, it returns a newOptional
j 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