SlideShare a Scribd company logo
Java 9 Features with Examples
Presented By: Sonu Singh
Agenda Differences with lower version
●
Try with Resources Enhancement
●
Private method inside Interface
●
Factory Method to create Unmodifiable
collections
●
Http/2 client
New Features in Java language
●
Jshell
●
JPMS(Java Platform Module System)
●
Jlink(Java Linker)
●
Process API updates
Jshell
●
JShell is a REPL (Read-Evaluate-Print Loop).
●
A command line tool which allows developer to coding in java without building projects in IDEs
●
Compiling and Running their short code.
●
Jshell is similar with interpreted languages like Python or other JVM languages like Groovy or Scala.
●
Running JShell is just... typing jshell in your Terminal
Private method inside Interface
● Java 9 onward, you are allowed to include private methods in interfaces.
● Using private methods, now encapsulation is possible in interfaces as well.
● Interfaces till Java 7:
In Java 7 and all earlier versions, interfaces were very simple. They could only contain public abstract
methods. These interface methods MUST be implemented by classes who implementing the interface.
● Static and defaults methods since Java 8:
From Java 8, apart from public abstract methods, you can have public static methods and public default
methods.
Using private methods in interfaces have four rules :
● Private interface method cannot be abstract.
● Private method can be used only inside interface.
● Private static method can be used inside other static and non-static interface methods.
● Private non-static methods cannot be used inside private static methods
Private method inside
Interface
Factory method with
Unmodifiable Collections
Creating immutable collections. Until Java 8, if we wanted to create immutable collections, we used to call
unmodifiableXXX() methods on java.util.Collections.
Create Immutable List
●
Use List.of() static factory methods to create immutable lists.
●
The List instances created by these methods have the following characteristics:
●
These lists are immutable. Elements cannot be added, removed, or replaced in these lists. Calling any
mutator method (i.e. add, addAll, clear, remove, removeAll, replaceAll) will always cause
UnsupportedOperationException to be thrown.
●
They do not allow null elements. Attempts to add null elements result in NullPointerException.
●
They are serializable if all elements are serializable.
The order of elements in the list is the same as the order of the provided arguments, or of the elements
in the provided array.
List<String> names = List.of("Lokesh", "Amit", "John");
Factory method with
Unmodifiable Collections
Create Immutable Set
●
Set behave very similar to List with only few differences. e.g.
●
Set do not allow duplicate elements as well. Any duplicate element passed will result in
IllegalArgumentException.
●
The iteration order of set elements is unspecified and is subject to change.
●
All Set factory methods have the same signature as List
Create Immutable Map
●
Map factory methods are same as List or Set overloaded factory methods. Only difference is that the
signatures of the of methods take alternating keys and values as arguments.
●
A resource is an object that must be closed once your program is done using it.
For example a File resource or JDBC resource for database connection or a Socket connection resource. Before Java 7, there was no auto resource
management and we should explicitly close the resource once our work is done with it. Usually, it was done in the finally block of a try-catch statement.
This approach used to cause memory leaks and performance hit when we forgot to close the resource.
Java 6 and Earlier
●
try{
//open resources like File, Database connection, Sockets etc
} catch (FileNotFoundException e) {
// Exception handling like FileNotFoundException, IOException etc
}finally{
// close resources
}
Try with Resources Enhancement
JAVA 8
try( open resources here){
// use resources
} catch (FileNotFoundException e) {
// exception handling
}
// resources are closed as soon as try-catch block is executed.
In java 9:
try (fouts){
System.out.println("fjkdsfjkdshjsdfh");
}
System.out.println("Out of try-catch block.");
Try with Resources Enhancement
JPMS (Java Platform Module System) is the core highlight of new Java 9 release
●
Modules are (package-like) artifacts containing code,with metadata describing the module and also
its relation to other module.
●
It is also known as Project Jigshaw
Project Jigsaw
●
Make it easier for developers to construct and maintain libraries and large applications;
●
Improve the security and maintainability of Java SE Platform Implementations in general, and the
JDK in particular;
●
Enable improved application performance
Java Platform Module System
Reliable configuration — Developers have long suffered with the brittle, error-prone
class-path mechanism for configuring program components. The class path cannot express
relationships between components, so if a necessary component is missing then that will not be
discovered until an attempt is made to use it. The class path also allows classes in the same
package to be loaded from different components, leading to unpredictable behavior and difficult-to-
diagnose errors. The proposed specification will allow a component to declare that it depends upon
other components, as other components depend upon it.
Strong encapsulation — The access-control mechanism of the Java programming
language and the Java virtual machine provides no way for a component to prevent other
components from accessing its internal packages. The proposed specification will allow a
component to declare which of its packages are accessible by other components, and which are
not.
In order to see which modules are available within Java, we can enter the following command:
java –list-modules,java --describe-module java.sql
WHY?
●
The JPMS consists of providing support for writing modular applications as well as modularizing the JDK
source code as well. JDK 9 is coming with around 92 modules (changes are possible in GA release). Java
9 Module System has a “java.base” Module. It’s known as Base Module. It’s an Independent module and
does NOT dependent on any other modules. By default, all other modules are dependent on “java.base”.
In java modular programming-
●
A module is typically just a jar file that has a module-info.class file at the root.
●
To use a module, include the jar file into modulepath instead of the classpath. A modular jar file
added to classpath is normal jar file and module-info.class file will be ignored.
module-info.java
●
module helloworld { exports com.howtodoinjava.demo;}
●
module test {requires helloworld;}
●
There are following module which is used in java 9:
java.activation@9.0.4,java.base@9.0.4,java.corba@9.0.4
Java Platform Module System
●
Jlink is Java’s new command line tool through which we can create our own customized JRE.
●
Usually, we run our program using the default JRE, but in case if you want to create your own JRE,
then you can go with the jlink concept.
●
To execute this small “hello world” application, we require the following .class files:
– Test.class
– String.class
– System.class
– Object.class
●
Here, these 4 .class will be enough to run my application.
●
The default JRE provided by Oracle contains 4300+ predefined Java *.class files.
●
If I execute my “hello world” application with the default JRE, then all the predefined *.class files will
be executed. But if I only need 3-4 *.class files to execute my “hello world” application.
JLink
So using the default JRE means:
●
Waste of memory and a performance hit
●
Will not be able to develop microservices that contain very little memory.
You can find the java.base module in the path:
●
javajdk-9jmods
●
So just copy the java.base module and paste it into the folder that has the Test.class file. Now we
can create our own JRE by using the command:
●
jlink –module-path out –add-modules demoModule,java.base –output myjre
cd myjre
●
cd bin
●
java -m demoModule/knoldus.Test
HTTP/1.1 client was released on 1997. A lot has changed since. So for Java 9 a new API
been introduced that is cleaner and clearer to use and which also adds support for
HTTP/2. New API uses 3 major classes i.e. HttpClient, HttpRequest and HttpResponse.
To make a request, it is as simple as getting your client, building a request and sending it
as shown below:
Http/2 Client
•
In HTTP/1.1, we cannot have more than six connections open at a time, so every request has to wait for the others to
complete.To avoid this, developers are used to doing workaround as a best practice. Those best practices
include minifying, compressing, and zipping the files together, sprite images, etc. This can be eliminated by multiplexing in
HTTP /2. This means that HTTP/2 can send multiple requests for data in parallel over a single TCP connection.
•
Text is replaced by Binary in HTTP/2.0
•
In an HTTP/1.1 environment, an HTML page is sent to the browser. The browser has to parse it and decide which assets
are required, then request those assets from the server. This can be eliminated by Server Push in HTTP/2. It allows
servers to push responses proactively to the client instead of waiting for the new request to process.
•
In HTTP/1.1, every request sent to the server will have the header's additional data, which increases bandwidth.This can
be eliminated in HTTP/2.0 by having headers packed into one compressed block that will be sent as a unit and, once
transmission is finished, the header blocks are decoded. It uses HPack for header compression.
Advantages of HTTP/2
Process API updates
●
Among the API changes is the introduction of the ProcessHandle interface, which makes common
operations on native processes much easier.
●
Before Java 9, there was no standard solution to get the native ID of the current process. One could
use java.lang.management.ManagementFactory as follows:
In Java 9 we can use the pid() method of the current ProcessHandle :
long pid= ProcessHandle.current().pid();
Checking If a Process Is Currently Running
Process process = ProcessHandler.current();
boolean isAlive = process.toHandle.isAlive();
References
●
https://dzone.com/articles/java-9-modules-introduction-part-1
●
https://dzone.com/articles/java-9-
●
https://howtodoinjava.com/java9/
●
http://openjdk.java.net/projects/jigsaw/
●
http://www.journaldev.com/2389/java-8-features-with-examples
Java 9 Features

More Related Content

PDF
Java 9 New Features
Ali BAKAN
 
PDF
Java11 New Features
Haim Michael
 
PPTX
Java 8 presentation
Van Huong
 
PDF
Java 8 features
NexThoughts Technologies
 
PDF
Introduction to Java 11
Knoldus Inc.
 
PPTX
Java 8 Lambda and Streams
Venkata Naga Ravi
 
PPTX
Java 8 lambda
Manav Prasad
 
PPTX
java 8 new features
Rohit Verma
 
Java 9 New Features
Ali BAKAN
 
Java11 New Features
Haim Michael
 
Java 8 presentation
Van Huong
 
Java 8 features
NexThoughts Technologies
 
Introduction to Java 11
Knoldus Inc.
 
Java 8 Lambda and Streams
Venkata Naga Ravi
 
Java 8 lambda
Manav Prasad
 
java 8 new features
Rohit Verma
 

What's hot (20)

PDF
Java 10 New Features
Ali BAKAN
 
PPTX
Introduction to java
Sandeep Rawat
 
ODP
Java 9/10/11 - What's new and why you should upgrade
Simone Bordet
 
PPTX
Java 8 - An Overview
Indrajit Das
 
PDF
Java modules
Rory Preddy
 
ODP
Xke spring boot
sourabh aggarwal
 
PPTX
Apache tomcat
Shashwat Shriparv
 
PDF
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Edureka!
 
DOCX
JDK,JRE,JVM
Cognizant
 
PPTX
Core java
Ravi varma
 
PDF
Introduction to java (revised)
Sujit Majety
 
PPT
Spring Boot in Action
Alex Movila
 
PPTX
Spring Framework
tola99
 
PPT
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
PDF
Java8 features
Elias Hasnat
 
ODP
Introduction to Java 8
Knoldus Inc.
 
PPTX
Spring data jpa
Jeevesh Pandey
 
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
PPTX
Spring boot
sdeeg
 
PDF
Introduction to Spring Boot!
Jakub Kubrynski
 
Java 10 New Features
Ali BAKAN
 
Introduction to java
Sandeep Rawat
 
Java 9/10/11 - What's new and why you should upgrade
Simone Bordet
 
Java 8 - An Overview
Indrajit Das
 
Java modules
Rory Preddy
 
Xke spring boot
sourabh aggarwal
 
Apache tomcat
Shashwat Shriparv
 
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Edureka!
 
JDK,JRE,JVM
Cognizant
 
Core java
Ravi varma
 
Introduction to java (revised)
Sujit Majety
 
Spring Boot in Action
Alex Movila
 
Spring Framework
tola99
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Java8 features
Elias Hasnat
 
Introduction to Java 8
Knoldus Inc.
 
Spring data jpa
Jeevesh Pandey
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
Spring boot
sdeeg
 
Introduction to Spring Boot!
Jakub Kubrynski
 
Ad

Similar to Java 9 Features (20)

PPTX
Java 9 features
shrinath97
 
PPT
Features java9
srmohan06
 
PPTX
What’s expected in Java 9
Gal Marder
 
PDF
How can your applications benefit from Java 9?
EUR ING Ioannis Kolaxis MSc
 
PDF
How can your applications benefit from Java 9?
EUR ING Ioannis Kolaxis MSc
 
PDF
Java 9
Alican Akkuş
 
PDF
What to expect from Java 9
Ivan Krylov
 
PDF
Java features. Java 8, 9, 10, 11
Ivelin Yanev
 
PDF
Preparing your code for Java 9
Deepu Xavier
 
PDF
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
PDF
Haj 4344-java se 9 and the application server-1
Kevin Sutter
 
PDF
A Journey through the JDKs (Java 9 to Java 11)
Markus Günther
 
PDF
Java >= 9
Benjamin Pack
 
PPTX
Top 5 features added to Java 9
Ankur Srivastava
 
PDF
Java 9 New Features | Java Tutorial | What’s New in Java 9 | Java 9 Features ...
Edureka!
 
PPTX
DevNexus 2020: Discover Modern Java
Henri Tremblay
 
PDF
Illia shestakov - The Future of Java JDK #9
Anna Shymchenko
 
PPTX
Petro Gordiievych "From Java 9 to Java 12"
LogeekNightUkraine
 
PPTX
An introduction to Java 9 & Its Features
NexSoftsys
 
PPTX
Java 9
Netesh Kumar
 
Java 9 features
shrinath97
 
Features java9
srmohan06
 
What’s expected in Java 9
Gal Marder
 
How can your applications benefit from Java 9?
EUR ING Ioannis Kolaxis MSc
 
How can your applications benefit from Java 9?
EUR ING Ioannis Kolaxis MSc
 
What to expect from Java 9
Ivan Krylov
 
Java features. Java 8, 9, 10, 11
Ivelin Yanev
 
Preparing your code for Java 9
Deepu Xavier
 
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
Haj 4344-java se 9 and the application server-1
Kevin Sutter
 
A Journey through the JDKs (Java 9 to Java 11)
Markus Günther
 
Java >= 9
Benjamin Pack
 
Top 5 features added to Java 9
Ankur Srivastava
 
Java 9 New Features | Java Tutorial | What’s New in Java 9 | Java 9 Features ...
Edureka!
 
DevNexus 2020: Discover Modern Java
Henri Tremblay
 
Illia shestakov - The Future of Java JDK #9
Anna Shymchenko
 
Petro Gordiievych "From Java 9 to Java 12"
LogeekNightUkraine
 
An introduction to Java 9 & Its Features
NexSoftsys
 
Java 9
Netesh Kumar
 
Ad

More from NexThoughts Technologies (20)

PDF
Alexa skill
NexThoughts Technologies
 
PDF
Docker & kubernetes
NexThoughts Technologies
 
PDF
Apache commons
NexThoughts Technologies
 
PDF
Microservice Architecture using Spring Boot with React & Redux
NexThoughts Technologies
 
PDF
Solid Principles
NexThoughts Technologies
 
PDF
Introduction to TypeScript
NexThoughts Technologies
 
PDF
Smart Contract samples
NexThoughts Technologies
 
PDF
My Doc of geth
NexThoughts Technologies
 
PDF
Geth important commands
NexThoughts Technologies
 
PDF
Ethereum genesis
NexThoughts Technologies
 
PPTX
Springboot Microservices
NexThoughts Technologies
 
PDF
An Introduction to Redux
NexThoughts Technologies
 
PPTX
Google authentication
NexThoughts Technologies
 
Docker & kubernetes
NexThoughts Technologies
 
Apache commons
NexThoughts Technologies
 
Microservice Architecture using Spring Boot with React & Redux
NexThoughts Technologies
 
Solid Principles
NexThoughts Technologies
 
Introduction to TypeScript
NexThoughts Technologies
 
Smart Contract samples
NexThoughts Technologies
 
My Doc of geth
NexThoughts Technologies
 
Geth important commands
NexThoughts Technologies
 
Ethereum genesis
NexThoughts Technologies
 
Springboot Microservices
NexThoughts Technologies
 
An Introduction to Redux
NexThoughts Technologies
 
Google authentication
NexThoughts Technologies
 

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Software Development Company | KodekX
KodekX
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Software Development Methodologies in 2025
KodekX
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Software Development Company | KodekX
KodekX
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 

Java 9 Features

  • 1. Java 9 Features with Examples Presented By: Sonu Singh
  • 2. Agenda Differences with lower version ● Try with Resources Enhancement ● Private method inside Interface ● Factory Method to create Unmodifiable collections ● Http/2 client New Features in Java language ● Jshell ● JPMS(Java Platform Module System) ● Jlink(Java Linker) ● Process API updates
  • 3. Jshell ● JShell is a REPL (Read-Evaluate-Print Loop). ● A command line tool which allows developer to coding in java without building projects in IDEs ● Compiling and Running their short code. ● Jshell is similar with interpreted languages like Python or other JVM languages like Groovy or Scala. ● Running JShell is just... typing jshell in your Terminal
  • 4. Private method inside Interface ● Java 9 onward, you are allowed to include private methods in interfaces. ● Using private methods, now encapsulation is possible in interfaces as well. ● Interfaces till Java 7: In Java 7 and all earlier versions, interfaces were very simple. They could only contain public abstract methods. These interface methods MUST be implemented by classes who implementing the interface. ● Static and defaults methods since Java 8: From Java 8, apart from public abstract methods, you can have public static methods and public default methods.
  • 5. Using private methods in interfaces have four rules : ● Private interface method cannot be abstract. ● Private method can be used only inside interface. ● Private static method can be used inside other static and non-static interface methods. ● Private non-static methods cannot be used inside private static methods Private method inside Interface
  • 6. Factory method with Unmodifiable Collections Creating immutable collections. Until Java 8, if we wanted to create immutable collections, we used to call unmodifiableXXX() methods on java.util.Collections. Create Immutable List ● Use List.of() static factory methods to create immutable lists. ● The List instances created by these methods have the following characteristics: ● These lists are immutable. Elements cannot be added, removed, or replaced in these lists. Calling any mutator method (i.e. add, addAll, clear, remove, removeAll, replaceAll) will always cause UnsupportedOperationException to be thrown. ● They do not allow null elements. Attempts to add null elements result in NullPointerException. ● They are serializable if all elements are serializable.
  • 7. The order of elements in the list is the same as the order of the provided arguments, or of the elements in the provided array. List<String> names = List.of("Lokesh", "Amit", "John");
  • 8. Factory method with Unmodifiable Collections Create Immutable Set ● Set behave very similar to List with only few differences. e.g. ● Set do not allow duplicate elements as well. Any duplicate element passed will result in IllegalArgumentException. ● The iteration order of set elements is unspecified and is subject to change. ● All Set factory methods have the same signature as List Create Immutable Map ● Map factory methods are same as List or Set overloaded factory methods. Only difference is that the signatures of the of methods take alternating keys and values as arguments.
  • 9. ● A resource is an object that must be closed once your program is done using it. For example a File resource or JDBC resource for database connection or a Socket connection resource. Before Java 7, there was no auto resource management and we should explicitly close the resource once our work is done with it. Usually, it was done in the finally block of a try-catch statement. This approach used to cause memory leaks and performance hit when we forgot to close the resource. Java 6 and Earlier ● try{ //open resources like File, Database connection, Sockets etc } catch (FileNotFoundException e) { // Exception handling like FileNotFoundException, IOException etc }finally{ // close resources } Try with Resources Enhancement
  • 10. JAVA 8 try( open resources here){ // use resources } catch (FileNotFoundException e) { // exception handling } // resources are closed as soon as try-catch block is executed. In java 9: try (fouts){ System.out.println("fjkdsfjkdshjsdfh"); } System.out.println("Out of try-catch block.");
  • 11. Try with Resources Enhancement
  • 12. JPMS (Java Platform Module System) is the core highlight of new Java 9 release ● Modules are (package-like) artifacts containing code,with metadata describing the module and also its relation to other module. ● It is also known as Project Jigshaw Project Jigsaw ● Make it easier for developers to construct and maintain libraries and large applications; ● Improve the security and maintainability of Java SE Platform Implementations in general, and the JDK in particular; ● Enable improved application performance Java Platform Module System
  • 13. Reliable configuration — Developers have long suffered with the brittle, error-prone class-path mechanism for configuring program components. The class path cannot express relationships between components, so if a necessary component is missing then that will not be discovered until an attempt is made to use it. The class path also allows classes in the same package to be loaded from different components, leading to unpredictable behavior and difficult-to- diagnose errors. The proposed specification will allow a component to declare that it depends upon other components, as other components depend upon it. Strong encapsulation — The access-control mechanism of the Java programming language and the Java virtual machine provides no way for a component to prevent other components from accessing its internal packages. The proposed specification will allow a component to declare which of its packages are accessible by other components, and which are not. In order to see which modules are available within Java, we can enter the following command: java –list-modules,java --describe-module java.sql WHY?
  • 14. ● The JPMS consists of providing support for writing modular applications as well as modularizing the JDK source code as well. JDK 9 is coming with around 92 modules (changes are possible in GA release). Java 9 Module System has a “java.base” Module. It’s known as Base Module. It’s an Independent module and does NOT dependent on any other modules. By default, all other modules are dependent on “java.base”.
  • 15. In java modular programming- ● A module is typically just a jar file that has a module-info.class file at the root. ● To use a module, include the jar file into modulepath instead of the classpath. A modular jar file added to classpath is normal jar file and module-info.class file will be ignored. module-info.java ● module helloworld { exports com.howtodoinjava.demo;} ● module test {requires helloworld;} ● There are following module which is used in java 9: [email protected],[email protected],[email protected] Java Platform Module System
  • 16. ● Jlink is Java’s new command line tool through which we can create our own customized JRE. ● Usually, we run our program using the default JRE, but in case if you want to create your own JRE, then you can go with the jlink concept. ● To execute this small “hello world” application, we require the following .class files: – Test.class – String.class – System.class – Object.class ● Here, these 4 .class will be enough to run my application. ● The default JRE provided by Oracle contains 4300+ predefined Java *.class files. ● If I execute my “hello world” application with the default JRE, then all the predefined *.class files will be executed. But if I only need 3-4 *.class files to execute my “hello world” application. JLink
  • 17. So using the default JRE means: ● Waste of memory and a performance hit ● Will not be able to develop microservices that contain very little memory. You can find the java.base module in the path: ● javajdk-9jmods ● So just copy the java.base module and paste it into the folder that has the Test.class file. Now we can create our own JRE by using the command: ● jlink –module-path out –add-modules demoModule,java.base –output myjre cd myjre ● cd bin ● java -m demoModule/knoldus.Test
  • 18. HTTP/1.1 client was released on 1997. A lot has changed since. So for Java 9 a new API been introduced that is cleaner and clearer to use and which also adds support for HTTP/2. New API uses 3 major classes i.e. HttpClient, HttpRequest and HttpResponse. To make a request, it is as simple as getting your client, building a request and sending it as shown below: Http/2 Client
  • 19. • In HTTP/1.1, we cannot have more than six connections open at a time, so every request has to wait for the others to complete.To avoid this, developers are used to doing workaround as a best practice. Those best practices include minifying, compressing, and zipping the files together, sprite images, etc. This can be eliminated by multiplexing in HTTP /2. This means that HTTP/2 can send multiple requests for data in parallel over a single TCP connection. • Text is replaced by Binary in HTTP/2.0 • In an HTTP/1.1 environment, an HTML page is sent to the browser. The browser has to parse it and decide which assets are required, then request those assets from the server. This can be eliminated by Server Push in HTTP/2. It allows servers to push responses proactively to the client instead of waiting for the new request to process. • In HTTP/1.1, every request sent to the server will have the header's additional data, which increases bandwidth.This can be eliminated in HTTP/2.0 by having headers packed into one compressed block that will be sent as a unit and, once transmission is finished, the header blocks are decoded. It uses HPack for header compression. Advantages of HTTP/2
  • 20. Process API updates ● Among the API changes is the introduction of the ProcessHandle interface, which makes common operations on native processes much easier. ● Before Java 9, there was no standard solution to get the native ID of the current process. One could use java.lang.management.ManagementFactory as follows:
  • 21. In Java 9 we can use the pid() method of the current ProcessHandle : long pid= ProcessHandle.current().pid(); Checking If a Process Is Currently Running Process process = ProcessHandler.current(); boolean isAlive = process.toHandle.isAlive();

Editor's Notes

  • #23: All the Java Stream API interfaces and classes are in the java.util.stream package. Since we can use primitive data types such as int, long in the collections using auto-boxing and these operations could take a lot of time, there are specific classes for primitive types – IntStream, LongStream and DoubleStream.