Java 9, 10 and 11: Pitfalls for the Unwary
Speaker: Simon Ritter
For more blog posts, seeÂ The Oracle Code One table of contents
- If you aren’t already on Java 9 or 10, don’t upgrade to them. Go straight to Java 11. Java 9 and 10 are feature releases, not LTS releases
- Compatibility has always been very important
- A few exceptions, but not significant. Was a pattern match search and replace
- 1.4 – couldn’t use name assert anymore
- 1.5 – couldn’t use name enum anymore
- Concept of deprecation added in 1.1 – statement that a newer version is better
- Java 8 has 492 deprecated API elements and non had ever been removed
- Going forward, get at least one release or warning. Noted that less than that would be no warning at all.
- Starting Java 9, things getting removed.
- “if your code only uses standard Java APIs, it will most likely work” – Mark Reinhold
Java 9 – Module system
- 75 OpenJDK modules
- 27 Java SE, 48 JDK (ex: tools)
- Oracle JDK adds 14 more JDK, 8 Java FX and 2 Oracle specific. Applies to Java 9. Remember Oracle JDK 11 == Open JDK 11
- Most internal APIs are now encapsulated
- sun.misc.Unsafe – the clue is in the name. Everyone has used through open source library like spring
- Can choose not to use modules. Leave everything on classpath. Everything is in the unnamed module which depends on all modules. All packages are exported.
- Then can migrate to modules gradually. Try automatic modules where don’t have module-info.class file but still treat as module.
- Try moving existing jar files from classpath to modulepath.
- “Big Kill Switch” –illegal-access
- permit – warn for first use of encapsulated API
- warn – warn for every use of encapsulated API
- debug – warn and provide stack trace for every use
- deny – don’t allow use at all
- At some point, the default will become deny. We don’t know when. Suspect it’ll be a good while.
- Allow direct access to encapsulated APIS — add exports
- List package names exposing. Can be to ALL-UNNAMED or to specific packages
- Alternatively can do this in the jar file manifest. That way library can expose without users having to specify
- ‘Allow reflective access to encapsulated API –add-opens
- List package names you want to expose
- find dependencies so can see which modules using
- includes jdk.unsupported which is where sun.unsafe lives
- java.se – aggregator module – If just use java.se, everything should just work
- java.se.ee – module not included by default in JDK 9/10
- ex: corba, transactions, Java activation (beans activation framework), xml bind (JAXB), web services (SOAP based)
- Audience survey showed a lot of people using SOAP based web services
- Still affected if use Apache SOAP library because sits on top of java library
- –add-modules – to explicitly add
- Use standalone package from Maven central – deploy to upgrade module path or standalone version on classpath
- Single underscore is now a keyword. Can no longer use as an identifier. Can use two or more underscores if really want underscore variable name. Will be introducing _ as lambda dummy parameter.
- Deleted some deprecated methods
- New tool in Java 9: jdeprscan – static analysis against class files and jar files to report Java SE deprecated APIs
- JDK/JRE file structure changed. Flatter directory structure. Now have bin/conf/lib/jmods.
- lib/ext and lib/endorsed removed. If create directory, get fatal error starting JDK. Fails fast!
- JNLP (Java Network Launch Protocol) – now uses strict parsing
- Removed lots of JVM flags and others were replaced with different flags.
- Version string format has changed. Was 1.8.0_131.
- Fun fact. JDK 7u55 has more patches than JDK 7u60
- New format $FEATURE.$INTERIM.$UPDATE.$PATCH
- Feature – main version number
- Interim – always 0 – reserved for future use
- Update – 0, 1, 2
- Patch – for emergency updates
- var is now a reserved type. Not a reserved word. Can still use as variable name. Can’t create class called “var”.
- Removed for deprecated code.
- javah tool removed (for JNI). How do javac -h
- policytool also removed
- Oracle JDK – commercial license
- Oracle Open JDK JDK – Mark Reinhold wants OpenJDK to be an adjective; not a noun. [because people are going to say that?}
- Browser plugin going away
- Java Web Start going away. Some alternatives, but no drop in replacement.
- jmc (monitoring/mission control) – now a standalone package
- More deprecated code removed
My take: Great humor. And great review for the stuff I knew. Also good clarifications and learning for the parts I did not know. There were a lot of references to Java 9 and 10. For most things, these apply to 11 as well. In a few case, it was confusing what applied to 11 vs what was interim.