What is a Java module?

A Java module is a collection of classes in a JAR or in a directory that also contains a special class named module-info. If there is this file in a JAR or directory, then it is a module, otherwise, it is just a collection of classes that are on the classpath (or not). Java 8, and the earlier versions will just ignore that class as it is never used as code. This way, using older Java, causes no harm, and backwards compatibility is maintained.

To create such a JAR is a bit tricky. The module-info.class file should have bytecode that conforms to Java 9 bytecode or later, but the other classes should contain older version bytecodes.

The module information defines what the module exports and what it requires. It has a ...

Get Java Projects - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.