Java 9 : What's new !
Java 9 has been much awaited ever since the release of Java 8 , almost three years back.
Expected finally to be released on September 21st, 2017, Java 9 shall be shipped with a host of new features , 'Modules' being the most important of those.
Let us see Modules as well as others in a nutshell
1. Modules :
‘module is a named, self-describing
collection of code and data. Its code is organized as a set of packages
containing types, i.e., Java classes and interfaces; its data includes
resources and other kinds of static information.’
Think about scalability. JDK is a bundled set of jars required
to be downloaded as whole. What do we do when we try scale? We break into
independent pieces, that can communicate
with each other as and when required.
Java came up with multiple modules in JDK to make it light
weight, and scalable.
With Help of Linker , these modules could be linked together at runtime , thus making the age old and heavy RT.jar unnecessary.
If we look into the JDK structure now, we find all components now put as modules inside lib/src folder. Each module now contains its own module-info.java
JDK structure |
Here is what a module-info.java looks like : | |
Note the contents in above module-info.java, which is
also called Module Descriptor. Java 9 introduces two new statements ; ‘requires’
and ‘export’
‘requires’ is analogous to import . Dependencies on other modules are expressed
through`requires` statements. Whereas ‘exports’ specifies the packages
inside current module , that are exposed and can be required by other modules .
We can create our own modules in similar pattern and provide dependencies and expose our module's packages.
2. JLink :
'The jlink
tool defines a plugin mechanism for transformation and optimization during the
assembly process, and for the generation of alternative image formats. It can
create a custom runtime optimized for a single program. JEP 261
defines link time as an optional phase between the phases of compile time and
run time. Link time requires a linking tool that assembles and optimizes a set
of modules and their transitive dependencies to create a runtime image or
executable.' -- from oracle docs.
Java 9 introduces a runtime linking tool , which can map all dependencies between different modules at runtime .
A basic invocation of jlink has following format :
$ jlink --module-path <modulepath> --add-modules <modules> --limit-modules <modules> --output <path>
Where :
-
--module-path
is the path where observable modules will be discovered by the linker; these can be modular JAR files, JMOD files, or exploded modules
-
--add-modules
names the modules to add to the run-time image; these modules can, via transitive dependencies, cause additional modules to be added
-
--limit-modules
limits the universe of observable modules
-
--output
is the directory that will contain the resulting run-time image
3. JShell :
jshell
tool provides an interactive command-line
interface for evaluating declarations, statements, and expressions of the Java
programming language. It facilitates prototyping and exploration of coding
options with immediate results and feedback. The immediate feedback combined
with the ability to start with expressions is useful for education—whether
learning the Java language or just learning a new API or language feature.One can launch jshell by simply typing 'jshell' in command window. for mac , you can simply launch the jshell.exe from /bin/ folder in jdk.
Here is sample window :
JShell on Terminal |
4. JAVA Docs :
The new improved Java docs now come with a search option , using which you can easily search any API. The Doc pages are now HTML5 enabled and hence give a better user experience.
Java 9 Docs EA |
5. Java Language Changes
There are minor but multiple change in Java SE 9
· Allow
@SafeVargs
on private
instance methods.
· Allow
effectively-final variables to be used as resources in the
try-with-resources
statement.
· You can use diamond syntax in conjunction
with anonymous inner classes.
· Underscore character is not a legal name
· Private
interface methods are supported. This support allows nonabstract methods of an
interface to share code between them.
6. JVM and JVM tuning:
Some minor changes related to garbage collection , and JVM processes are listed below . You can go through details on the oracle documentation if you are interested :
JVM
- Compiler Control
- Segmented Code Cache
- Dynamic Linking of Language Defined Object models
GC
- G1 is the default GC now
- Unified GC logging
- Unified JVM loging
- Concurrent Mask Sweep Alogorithms deprecated
Comments
Post a Comment