What is a Java module

A Java module is a collection of classes in a JAR or in a directory that also contain 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 backward compatibility is maintained.

The module information defines what the module exports and what it requires. It has a special format. For example, we can place module-info.java in our SortInterface Maven module.

module packt.java9.by.example.ch03{         exports packt.java9.by.example.ch03;         }

This means that any class, ...

Get Java 9 Programming By Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.