JVM Specialty Group December 2018 Meeting

Wednesday, December 19, 2018

Introduction to the Java Module System

Presenter: Andrej Rasevic

Wednesday, December 19, 2018

Introduction to the Java Module System

Desired outcomes:

  • understand why was the module system necessary
  • create and run a java module-based application 
  • what problems does it solve and what are its principal benefits
  • get our hands dirty with the new module system

Wednesday, December 19, 2018

Introduction to the Java Module System

Why was the module system necessary - motivation & background

 

Improved separation of concerns

  • more able to work on individual parts in isolation
  • facilitate reuse of parts
  • easier maintenance of overall systems

how does an application benefit from a modular system?

Wednesday, December 19, 2018

Introduction to the Java Module System

Why was the module system necessary - motivation & background

 

Increased encapsulation and information hiding

how does an application benefit from a modular system?

  • compiler can now check that classes and packages are available only for their intended purposes

Wednesday, December 19, 2018

Introduction to the Java Module System

Why was the module system necessary - motivation & background

 

Modularity limitations

  • Java grouped code at 3 levels (classes, packages and JARS)
  • supported access modifiers and encapsulation for classes
  • little encapsulation at the package and JAR level

Wednesday, December 19, 2018

Introduction to the Java Module System

Why was the module system necessary - motivation & background

 

Limited visibility control

  • Java provides public, private, protected and package level visibility for classes
  • If you want to share classes and interfaces from one package with another, you must declare them as public
  • exposes your classes and interfaces to everyone allowing for increased security risks 

Wednesday, December 19, 2018

Introduction to the Java Module System

Why was the module system necessary - motivation & background

 

CLASS PATH HELL

  • distribute all compiles classes as single flat JAR which are lazily loaded by the CLASS PATH
  • CLASS PATH cannot differentiate between different versions of the same class on the class path
  • doesn't support explicit dependencies
  • all classes of different JARs are merged into one bag of classes on the class path
  • impossible to ask if anything is missing or are there any conflicts

Wednesday, December 19, 2018

Introduction to the Java Module System

Why was the module system necessary - motivation & background

 

Monolithic JDK

JDK is a collection of tools that lets you work with and run java programs  

  • javac - lets you compile Java programs

  • java along with JDK library allow you to load and run Java program

  • what does CORBA do for you?
  • especially problematic for mobile or cloud based applications that don't need all the available parts of the JDK library

Wednesday, December 19, 2018

Introduction to the Java Module System

Jigsaw-puzzle style of representation of a Java system

Wednesday, December 19, 2018

Introduction to the Java Module System

module com.foo { 
  requires com.bar;
  exports com.foo;  
}

In order to become a module, a project must have a module-info.java file at the root of the project's source

Wednesday, December 19, 2018

Introduction to the Java Module System

Modules are very similar to JAR's in that they are container's for types and resources

Modules differ from JAR's by having additional characteristics

  • a name, preferably one that is globally unique
  • declarations of dependancies on other modules
  • clearly defined API that consists of exported packages

Wednesday, December 19, 2018

Introduction to the Java Module System

JDK was broken up into over 100 platform modules

If you want to see them, execute: java --list-modules

Let's run it in the terminal...

Now if we want to inspect a specific module you can run: java --describe-module ${module}

Let's see what the java.sql module API looks like

Wednesday, December 19, 2018

Introduction to the Java Module System

Let's take a look at an example of using Java modules

Java Specialty Group December 2018

By arasevic

Java Specialty Group December 2018

  • 363