Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 61 path to java 9 In order to fit some minor file information has been removed from this listing Ed There are a few things to see here but lets start with the big news the jre directory is gone There is no more rt jar to contain the whole of the JRE Instead the JRE is stored in the new jimage format This is a container format that manages classes and resources needed by the modularized runtime Rather than traditional zip based compression jimage files are indexed to support fast lookup of classes and resources The content region of a jimage contains all classes and resources for the image and is managed in terms of locations Resources can be located in the index by using a module path as a search key The path format is module name package base name extension Paths are versioned and the current path is 90 this reflects the current release of the JVM The main jimage file is found in lib modules and is called bootmodules jimage However in addition to the jimage files there are also jmod files Java modules These files are being used as a test bed for other module features outside of the efforts in jimage to speed up access As it stands now jmod files are still implemented as zip files but the format will almost certainly change in future The fact that there are two packaging formats shows how much of a moving target Java 9 modules really are at present The java base jmod file contains the minimal viable collection of classes for any nontrivial Java program to run It contains the following packages or subsets of them java io java lang java math java net java nio java security java text java time java util javax crypto javax net javax security The rest of the module consists of the implementation classes to support the base module Of course the real intent of Project Jigsaw is that Java developers also make use of the mechanism to produce modular libraries and applications of their own Lets take a quick look into this world by considering a simple Hello World for modules A simple Java module To create a very simple Java module we need to write two parts the first of which is a simple core class such as this package com jdk9ex public class Main public static void main String args System out println Hello Modules In Java 8 and earlier this code could be compiled and run without further ceremony However to run correctly in modular Java this needs to be supplemented with a new piece of metadata a module info java file The intention is that this file will become a fairly sophisticated metadata provider and handle versioning and other important features of modules but the currently shipping version in Jigsaw EA is quite primitive and is only intended to allow keen developers to start investigating module technology The simplest module looks like this assuming our module for JDK 9 examples is named com jdk9ex module com jdk9ex
You must have JavaScript enabled to view digital editions.