Java 9

Java 9
Jigsaw -> Modularity
 
rt.jar contains 5000 plus classes & size is 65MB.
Are we using all these classes? Answer is no
JDK create approximetely 98 modules. Whichever set required. You can use them. If you want a specific module for use system takes the dependencies automatically.
Module dependency hierachy
jdk-9 (instead jdk1.9)
jmods folder available in the jdk-9 (98 modules) whichever modules required we can use as per our need.
  • java.base.jmod
  • java.desktop.jmod
  • java.rmi.jmod
  • java.sql.jmod
  • java.sql.rowset.jmod
  • java.se.jmod
  • java se.ee.jmod
  • java.logging.jmod
sql
|---> logging
|---> xml   |----->base
corba
|---> rmi --> logging -> base
|--->desktop  |--> xml---> base
              |---> charsets-->base


Currently we bundle the packages which consist of clasess and interface in jar and we use it.
package a.b
package a.b.c
Both packages are have no relationship. but we bundle it in the single jar.
Package is belong to module. Jar is a phyiscal holder of the module. Now package can be identified using module.

java.base is the base module.  (String, java.lang.classes and interface)

Module
A collection of code (package),has a name,tell what is needs (requires) & tell what is provides (exports)
 
Creating Modules:
  • Let's define a module
  • module-info.java in a top level directory
module com.developer.{
    exports com.dev.math;
}
com.developer (Module name) com.dev.math (packagename)
  • requires
  • export
  • to create a module
                  javac -d outputdir path/module-info.java path/package/sourcepath
                  jar -c -f mlib/filename.jar -C outputdir .
  • to use a module
  1.    javac -mp mlib ...
  2.    jar ... --main-class package.classname
  3.    java -mp mlib -m modulename
  4.         or
  5.    java -mp mlib -m module/package.mainclassname
Visibility:
  • Readability
  •    A module "reads" the modules it depends on
  • exports (package)
  • public is not the same any more (it is not visible outside)
  • public + exports becomes visible
  • public with no exports is not visible
  • that's both at compile time and runtime
No classpath, but we use module path

Dependency:
  • All modules depend on java.base
  • use jdeps to examine dependency
  •  -s option for summary
jdeps -s -mp out/mlib  jarName.jar 
com.developer -> java.base  (com.developer package depends on java.base package)
 
java -listmods  (what are the modules jvm using?)
 

Customize the module of your project using jlink

REPL - (Read Eval Print Loop) Interactive tool
jshell -> print the helloworld
 
Enhancement in Stream API  
Private method in Interface
public interface Demo{
   public void process();
   public default start(){  start1();}
   private void start1(){  }
}
Java JVM - G1 as default GC


Factory Methods for Immutable List, Set, Map and Map.Entry
 List<String> name = List.of("Peter", "Sam");

 Set<String> nameSet = List.of("Peter", "Sam");

Process API Improvements
Reactive Streams - Publisher,Subscriber,Processcor and Flow
Better @Deprecated Annotations
Http Client
HTML5 Java Doc
Search in Doc


Java 8 / 7 works in Java 9.
Java 9 focus on how we build and package them.
Java 8 focus on how to write the code effectively.

Comments

Popular posts from this blog

Robotic Process Automation

WorkFusion

7 Rules of Success A.P.J Abdul Kalam