Save 37% off PRO during our Black Friday Sale! »

A reasonable overview of Java 9 [Devoxx PL`2017]

A reasonable overview of Java 9 [Devoxx PL`2017]

The upcoming Java 9 release brings with it modularity, a new REPL, a new default garbage collector, HTTP 2 client, and much more. However, project Jigsaw requires so much of developer's attention that it's hard to see the true value of the upcoming release.

In this session we'll look at the features of Java 9 that developers not architects will face the most: welcome additions to the API: Optional, Date and Time, Stack walker, process management, collection literals (just kidding, they are factories of course), performance improvements, where to find the Unsafe and how to treat it after all. Is JShell a real tool or a toy to run fun one-liners?

Should you rush to migrate to Java 9, as you did with the Java 8 and those sweet lambdas? Are multi-release jars nice or a point of pain?

In this session we'll try to answer whether it is all worth it and how could you proceed with it.

5d01eb7205b787b5991db85a11ee5e68?s=128

Oleg Šelajev

June 22, 2017
Tweet

Transcript

  1. JAVA 9 A REASONABLE OVERVIEW Oleg Šelajev ZeroTurnaround @shelajev

  2. @shelajev

  3. None
  4. WHAT’S JAVA 9 CODE NAME?

  5. None
  6. Safe harbour and stuff wARNING!! Sarcasm ahead!

  7. September 21st

  8. None
  9. None
  10. None
  11. None
  12. None
  13. None
  14. IDE SUPPORT

  15. http://0t.ee/rebellabs-survey-2017

  16. http://openjdk.java.net/projects/jigsaw/ JEP 200: The Modular JDK JEP 220: Modular Run-Time

    Images JEP 260: Encapsulate Most Internal APIs JEP 261: Module System JEP 282: jlink: The Java Linker JSR 376: JAVA PLATFORM MODULE SYSTEM
  17. None
  18. None
  19. None
  20. AREN’T MODULES EXCITING?

  21. module org.shelajev.N { requires com.google.guava; requires transitive com.shelajev.api; requires static

    compile.time.dependency; requires transitive static and.its.dependencies; exports public.classes.in.these.packages; exports some.packages to specific.modules; opens packages.for.reflection.and.public; opens these.packages to specific.modules, and.others; uses some.service.api; provides some.api with some.implementation; }
  22. MECHANISM COMPILE ACCESS REFLECTION ACCESS export all code > public

    all code > public qualified export specified modules > public specified modules > public open package none all code > private qualified open package none specified modules > private open module none all code > private https://blog.codefx.org/java/reflection-vs-encapsulation/
  23. --add-exports <source-module>/<package>=<target-module> --add-exports java.management/sun.management=ALL-UNNAMED --add-modules=java.xml.bind COMMAND LINE FUN

  24. None
  25. None
  26. WHAT’S DOES method.isAccessible() RETURN?

  27. None
  28. AUTOMATIC MODULES Any JAR on the module path without a

    module descriptor is an automatic module. Automatic modules implicitly export all their packages and read all other modules.
  29. --module-path --classpath Modular JAR application module unnamed module Non-Modular JAR

    automatic module unnamed module
  30. --ILLEGAL-ACCESS=PERMIT 1 WARNING, OTHERWISE LIKE CLASSPATH

  31. MIGRATION STRATEGY

  32. LET’S TALK ABOUT MAVEN

  33. None
  34. PETCLINIC APP [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.6:jar (default-jar) on

    project spring- petclinic: Execution default-jar of goal org.apache.maven.plugins:maven-jar-plugin:2.6:jar failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-jar-plugin:2.6:jar: java.lang.ExceptionInInitializerError: null
  35. Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)

    throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @4b9e00f3 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:337) ~[na:na] at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:281) ~[na:na] at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:198) ~[na:na] at java.base/java.lang.reflect.Method.setAccessible(Method.java:192) ~[na:na] at org.springframework.cglib.core.ReflectUtils$1.run(ReflectUtils.java:54) ~[na:na] at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na] at org.springframework.cglib.core.ReflectUtils.<clinit>(ReflectUtils.java:44) ~[na:na] ... 38 common frames omitted PETCLINIC APP built on Java 8, running Java 9
  36. PETCLINIC APP built on Java 8, running Java 9 with

    --permit-illegal-access Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:553) ~[na:na] at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) ~[spring-petclinic-1.5.1.jar:1.5.1] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:486) ~[na:na] ... 34 common frames omitted
  37. PETCLINIC APP built on Java 8, running Java 9 with

    --permit-illegal-access and --add-modules java.se.ee
  38. None
  39. Multirelease JARs

  40. G1GC GC

  41. Generational GC

  42. G1GC

  43. @shipilev https://shipilev.net/jvm-anatomy-park/3-gc-design-and-pauses/

  44. https://2017.geekout.ee/videos/#day2-02

  45. mad skillz, amirite?

  46. JSON picture of a hipster

  47. import jdk.incubator.http.HttpClient; import jdk.incubator.http.HttpResponse; HttpClient.newHttpClient().send( newBuilder(URI.create("https://www.google.com")) .GET() .build(), HttpResponse.BodyHandler.asString()) .body();

    http2
  48. STRING PERFORMANCE JEP 254: Compact Strings Adopt a more space-efficient

    internal representation for strings. JEP 280: Indify String Concatenation Change the static String-concatenation bytecode sequence generated by javac to use invokedynamic calls to JDK library functions.
  49. None
  50. THINGS NOT TO TOUCH UNLESS YOU’RE 100% SURE multi-release jars

    jlink
  51. THINGS NOT TO TOUCH UNLESS YOU’RE 100% SURE multi-release jars

    jlink Unsafe
  52. Java 9, the cooking guide 1. Upgrade your IDE, your

    other tools 2. Upgrade Spring to 5.0 3. Add --illegal-access=warn a. fix easily fixable warnings 4. Wait 365 days (or more) on the classpath
  53. None
  54. None
  55. oleg@zeroturnaround.com @shelajev Find me and chat with me!