7. Dock it!
docker run -it openjdk:12-jdk
docker run -it openjdk:13-jdk
docker run -it openjdk:14-jdk
docker run -it amd64/openjdk:15-jdk-oracle /bin/jshell --enable-
preview
docker run -it openjdk:14-jdk /bin/bash
docker run -it -v $(pwd):/tmp openjdk:14-jdk /bin/bash
8. Java 9 new features
• Modular everything, yeah, we’ve covered that shock already – so you
made your transition to Jigsaw
• JShell
• Private methods in interfaces
• Optional.ifPresentOrElse(), Optional.or(),
Optional.stream()
• Immutable Collection Factories
• Set.of("John", "George", "Betty"); Map.of("John", 1,
"Betty", 2);
• New default GC: G1
9. Java 10 new features
• var keyword (local-variable type inference)
• Optional.orElseThrow()
• Unmodifiable collections
• List.copyOf(), Set.copyOf(), Map.copyOf()
• Collectors.toUnmodifiableList(),
Collectors.toUnmodifiableSet(),
Collectors.toUnmodifiableMap()
• Better G1: Parallel full GC
• Docker container aware (On Linux platforms)
10.
11. Java 11 new features
• Local-Variable Syntax for Lambda Parameters
• IntFunction<Integer> doubleIt2 = (var x) -> x * 2;
• IntFunction<Integer> doubleIt2 = (@Valid final var x) -> x * 2;
• Launch Single-File Source-Code Programs
• java SimpleProgram.java
• JDK API
• String::repeat, String::lines
• Optional::isEmpty
• Files::writeString
• Path::of
• ZGC garbage collector
13. Java 12 new features
• Preview: Switch statement may return value (JEP 325)
• JEP 341: Default CDS archives
• JEP 230 Microbenchmark suite
• Improved G1 GC: Abortable mixed collections for G1 (JEP 344),
Promptly return unused committed memory from G1 (JEP
346)
• Experimental; Shenandoah low-pause-time GC
14. var urlList = List.of(
"dev.solita.fi",
"secure.solita.fi"
);
var results = urlList.stream()
.map(x -> switch(x) {
case "dev.solita.fi" -> "ok";
default -> "nok";
}
)
.collect(Collectors.toList());
15. Class Data Sharing (CDS, JEP 341)
• Basically: Shared cache of architecture specific compilations, an
archive that can be shared across JVMs
• Caches preprocessed class metadata on disk, not same as AOT
• Skips class lookup, load, verification
• Eliminate out-of-the-box startup time
• Observe JDK lib/server folder, default, part of linked Java image
• Can be (re)created with –Xshare:dump
16. Short history of CDS
• Available already in SUN JVM 1.5,
• …but limited to client JVM, system classes and serial GC algorithm only
• Typically generated upon JRE installation
• Not same as code cache, metaspace, or permgen, as these are owned by each JVM
• OpenJDK/JDK 9, Supports server VM, G1, Serial, Parallel GCs
• Support for own application classes, but only in commercial version
• OpenJDK 10, JEP 310: Applicatiom class data sharing
• Java 12: JEP 341: Eliminate need to run –Xshare:dump to activate (means: regenerate
the archive)
• Currently: Limited, 64-bit only. To control further, -Xshare:auto, -Xshare:off, -Xshare:on
• Java 13: JEP 350
• Also: JEP 250, store interned strings in CDS
Also see: https://simonis.github.io/JEEConf2018/CDS/cds.xhtml
19. Java 13 new features
• JEP 350: Dynamic CDS Archives
• JEP 351: ZGC: Uncommit Unused Memory
• JEP 353: Reimplement the Legacy Socket API
• JEP 354: Switch Expressions (Preview)
• Continues work from Java 12 with yield keyword for blocks that return a
value
• More clarification: switch expression vs switch statement
• JEP 355: Text Blocks (Preview)
• Multiline text blocks, delimited by triple quotes
20. Verify latest Java features
var x = 1;
var y = switch(x) {
case 1: yield "ok";
case 2: yield "nok";
default: yield "wtf";
};
System.out.println(y);
21. Java 14 incoming features
• JEP 305: Pattern Matching for instanceof (Preview)
• JEP 343: Packaging Tool (Incubator)
• JEP 345: NUMA-Aware Memory Allocation for G1
(Physical memory sockets)
• JEP 349: JFR Event Streaming (Stream profiling and
diagnostic data from API)
• JEP 352: Non-Volatile Mapped Byte Buffers (Non-
Volatile Mapped Byte Buffers (persist data between
process runs)
• JEP 358: Helpful NullPointerExceptions (Helpful
NullPointerExceptions (Yay!)
• JEP 359: Records (Preview)
• JEP 361: Switch Expressions (Standard, go out of
preview)
• JEP 362: Deprecate the Solaris and SPARC Ports
• JEP 363: Remove the Concurrent Mark Sweep
(CMS) Garbage Collector (Byebye)
• JEP 364 and JEP 365 : ZGC on macOS and ZGC
on Windows
• JEP 366: Deprecate the ParallelScavenge +
SerialOld GC Combination
• JEP 367: Remove the Pack200 Tools and API
• JEP 368: Text Blocks (Second Preview)
• JEP 370: Foreign-Memory Access API (Incubator)
https://openjdk.java.net/projects/jdk/14/
23. Java 14 Records (preview)
record Point(int x, int y) { }
var r1 = new Point(10,20);
var r2 = new Point(10,20);
System.out.println(r1);
System.out.println(r1.equals(r2));
javac --enable-preview -source 14 RecordDemo.java
24. Java 15 incoming features
• https://openjdk.java.net/projects/jdk/15/
• https://bugs.openjdk.java.net/secure/Dashboard.jspa?selectPageId=19114
• JEP 198: Light-Weight JSON API (Candidate)
• JEP 218: Generics over Primitive Types (Candidate)
• JEP 301: Enhanced Enums (Candidate)
• JEP 302: Lambda Leftovers (Candidate)
• JEP 339: Edwards-Curve Digital Signature Algorithm (EdDSA) (Candidate)
• JEP 356: Enhanced Pseudo-Random Number Generators (Candidate)
• JEP 360: Sealed Types (Preview) (Candidate)
• JEP 371: Hidden Classes (Candidate)
Any attempt to modify such a collection would result in java.lang.UnsupportedOperationExceptionruntime exception.
You may need to provide --enable-preview and -source 11 flags to javac and --enable-preview flag to java.
https://stackify.com/java-12-new-features-and-enhancements-developers-should-know/
https://metebalci.com/blog/what-is-new-in-java-12/
You may need to provide --enable-preview and -source 12 flags to javac and --enable-preview flag to java.
Class Data-Sharing (CDS) is a feature to reduce startup time and benefit from memory sharing. However, if you do not install the JRE with the installer, the CDS archive is not generated by default and java -Xshare:dump has to be run manually.
This can be observed in JDK 11. If you install the JDK 11 GA Release from http://jdk.java.net/11/ , lib/server folder does not contain the CDS archive, classes.jsa file. If you run java -Xshare:dump, it will be generated.
With this JEP, CDS archive will be generated by default.
Ls /Library/Java/JavaVirtualMachines/adoptopenjdk-12.jdk/Contents/Home
Shenandoah
Once more, do GC while app keeps on running
Scale better by amount of memory
Experimental
var urlList = List.of("dev.solita.fi","secure.solita.fi");
var results = urlList.stream() .map(x -> switch(x) {
case "dev.solita.fi" -> "ok";
default -> "nok";
}).collect(Collectors.toList());
java -Xshare:off -jar libs/example-0.1-all.jar
[raaka@wickedwitch server]$ java -version
openjdk version "12.0.1" 2019-04-16
OpenJDK Runtime Environment AdoptOpenJDK (build 12.0.1+12)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 12.0.1+12, mixed mode, sharing)
https://metebalci.com/blog/what-is-new-in-java-13/
You may need to provide --enable-preview and -source 13 flags to javac and --enable-preview flag to java.
Limitation of using records:Records cannot extend any other class, and cannot declare instance fields other than the private final fields which correspond to components of the state description
Records are implicitly final, and cannot be abstract Such limitations underline that a record's API is entirely defined by its state definition and can not be modified by another class or record later.
The components of a record are implicitly final.
public record FXOrder(int units, CurrencyPair pair, Side side, double price, LocalDateTime sentAt, int ttl) {}