SlideShare ist ein Scribd-Unternehmen logo
1 von 48
9 New Features in Java 9
NETESH KUMAR
Overview
❏ JSHELL
❏ JPMS (Java Platform Module System)
❏ JLINK ( Java Linker)
❏ HTTP2/Client
❏ Process API Updates
❏ Private Method Inside Interface
❏ Factory Method For Unmodifiable Collection
❏ Stream API, Try With Resource & Diamond
Operator Enhancement
❏ Reactive Stream
❏ Others Change
JShell (Java Shell)
❏ JShell is the read-eval-print-loop (REPL) tool used for interacting quickly with java from
command line platform without the need to compile and run.
❏ Configure external editor with jshell.(/set editor “path” -w)
❏ Working with JAR/Module and file by setting classpath. (jshell --class-path “location”)
❏ It’s great for investigation of APIs that are unfamiliar to us.
❏ It’s wonderful for quick prototyping of tricky code. Like RegeX, Calculation based etc...
❏ Reference link:
❏ Link1
❏ Link2
JLink (Java Linker)
❏ Used for creating our own customize JRE
❏ Benefit:
❏ Smaller size of JAR.
❏ Suitable for IOT device and Microservices
❏ Running a simple JAR from anywhere even not required to pass “java” prefix.
Change in Interface
❏ Until now (Java 8), we can have only default, static and abstract method inside interface.
❏ From Java 9, we can have private method as well.
❏ Benefit:
❏ To avoid redundant code and more reusability
Immutable Collections
❏ Factory method for creating unmodifiable collections.
❏ Limitation:
❏ Can create only 0 to 10 size.
❏ But One method with varargs that let us create with desired number of element
❏ Benefit:
❏ Being shorter and nice to read
❏ List<String> string = List.of(“1” , ”2”);
❏ Set<Integer> set = Set.of(1,2);
❏ Map<Integer,Integer> map = Map.of(1,”a”,2,”b”);
❏ If we try to create with null element, a NullPointerException will be thrown.
❏ List<String> mutable = new ArrayList<>(List.of(“1”,”2”); mutable.add(null);
try-with-resource Improvement
❏ Till Java 8
void readFile() throw IOException{
BufferedReader reader1 = new
BufferedReader (new FileReader(“abc.txt”);
try(BufferedReader reader2 =reader){
System.out.println(reader2.readLine());
}
}
❏ Java 9
void readFile() throw IOException{
BufferedReader reader1 = new
BufferedReader (new FileReader(“abc.txt”);
try(reader1){
System.out.println(reader1.readLine());
}
}
Deprecated Enhancements
❏ Deprecated(since=”1.5” forRemoval=true)
❏ forRemoval:
❏ true means that “this API element is earmarked for removal in future
release”If they don’t migrate away from the APU, their code could be
break when new released is issued.
❏ false indicate that the API element is deprecated, but without any
specific intent to remove that API in the future.
❏ The default value for this element is false.
❏ since:
❏ The String should contain the release or version number at which this API
became deprecated.
❏ The default value of this element is empty string.
JPMS (Java Platform Module System)
❏ What is JPMS ?
❏ Why we need JPMS ?
❏ How JPMS will solve existing problem ?
Well know as Jigsaw project.
What is JPMS ?
❏ The Java Platform Module System is a self-describing collection of Code, Data and
some Resources. It is a set of related Packages, Types (classes, abstract classes,
interfaces etc) with Code & Data and Resources.
Any Confusion?
❏ If the idea of the module construct in java is simply to break code in
small encapsulated unit,then we could do it before java 9.
Question?
❏ Do you think, still we need Modularized JDK ?
❏ How will you control over class, package, jar etc...?
❏ What are the problem faced by developer in real life. ?
Problem with JAR or ClassPath (JAR HELL)
❏ NoClassDefFoundError in middle of program execution.
❏ Version Conflict.
❏ Security threat .
❏ Bigger size, Unable to fit in IOT device and Microservices.
Why JPMS ?
❏ Reliable configuration
❏ To provide better encapsulation, because public was too much public.
❏ To provide security
❏ Scalable java platform (in small memory we can run java application)
❏ Performance and Memory Improvement
❏ Question? What is special in java 9
How JPMS will solve existing problem ?
❏ Whole JDK is modularized.
❏ All predefined java class are divided in 98 module.
❏ Module contains configuration information inside a file “module-info.java”
❏ System.out.println(String.class.getModule());
Type of module
❏ There are three type of module.
❏ Named Module
❏ Unnamed module
❏ Automatic module
Type of module
❏ Named module
❏ A named module is a module created with a module declaration file module-info.java in its root
folder.
module module_name {
requires other_module_1;
exports package_name_1;
exports package_name to other_module; //
qualified export
opens some.client.package to framework.module;
}
Type of module
❏ Unnamed module
❏ Unnamed module is a jar built without module-info.java declaration. This means all
current jars built in Java 8 and earlier releases are unnamed modules.
❏ JVM choose unnamed module name always.
❏ What modules it 'requires'?
● The unnamed module 'requires' every other named modules automatically.
● That means all classes within the unnamed module can read all other module (named or
unnamed) without any explicit declaration of any kind.
● That also means that older classes (written prior to Java 9) can read all modules defined by
the new Module system.
Type of module
❏ Unnamed module
❏ What packages it 'exports'?
● The unnamed module 'exports' all its packages.
● That means different Jar applications which do not contain module or which are
compiled in the older versions, will continue to use each other's dependencies as it is.
● The packages exported by unnamed module can only be read by another unnamed
module.
❏ Do you have any question? Why unnamed module export all packages?
● This only ensure other unnamed modules can access its packages.
Behind the scenes for Unnamed Module
Unnamed module vs class path/module path
❏ Running using class path
Unnamed module vs class path/module path
❏ Running using module path
java --module-path out -module moduleName/com.netkumar.code.one.Unnamed
What are you going to use moduleName above?
We can’t run unnamed module name on module path.
❏ why don't we see all named modules of JSE 9 in above output.
● Java 9 import module on demand
Using --describe-module
❏ --describe-module <module name> is a java command option,which describes a module details.
❏ jar command also has --describe-module option which does not require a module name. It describes the
module in the specified jar.
Summary
● The unnamed module does not have module-info.java.
● The unnamed module 'requires' all other modules and 'exports' all its packages.
● The classes which were written in the older versions but now running in Java 9 environment will
continue to work because they become the members of the unnamed module.
● If we want to run old code in Java 9 environment without migrating them to the module system, we
should run them using class path (not module path)
Root Module
Let’s understand root module first.
What is 'requires transitive'
❏ Some modules which contain only module-info.java and no packages or no Java code. Their sole
purpose is to require other modules (called root modules) and make them visible outside. 'java.se' is
one of such module.
❏ 'requires transitive java.logging' will make java.logging available to the module which requires java.se
module.
❏ requires transitive == export or requires transitive != export ? what do you think about this ?
● 'exports' is used to make packages visible,
● 'requires transitive' is used to make imported modules visible outside.
Root Module
How root modules are used?
❏ When the Unnamed Module is being compiled or loaded, one of the set of root modules should be
accessible to the Unnamed module (so that a non-modular application will continue to work).
Type of module
What if a named module wants to read the existing jars or third party jar built without module-info.java
created?
Automatic module
❏ Java will create module from jar files automatically. These module are called Automatica module.
❏ The only thing you need to do is to put the jar file in the module path instead of the class path.
❏ Once a jar without module-info is put in the module path, it becomes an automatic module
automatically.
❏ An automatic module can read all other modules and all other modules can read it as well. Even the
named modules can read an automatic module.
❏ How automatic module will have a module name derived from its jar name? Do we have any rule ?
Automatic module
Rules:
● It drop the jar file extension
● It replace - character with .
● It remove the version string
What packages it 'exports'?
❏ It 'exports' all its packages.
What modules it 'requires'?
❏ It 'requires' all other modules on the module path.
Modularized JDK Image
Let’s Code
Live coding for below scenario
❏ Compatibility and Migration
❏ Split Packages
❏ Module Modes
❏ Modules and Services
❏ Qualified Exports
❏ Reflective Access
CLI Compilation: (Note:- share cheat sheet)
Javac --module-source-path “give module source path ” -d “where you want to
create out dir” “all java file or module name”
Java --module-path “out” --add-module “module name” “give main class”
Diamond operator ->Anonymous Inner
class❏ We can create <> operator for anonymous inner classes from JDK9.
Example:
List<String> list = new ArrayList<String>(){
{
add(“one”);
add(“two”);
}
}
SafeVarargs Enhancement
❏ We can apply @safevarargs annotation on private method from jdk9.
Example:
@safeVarargs
private static String getInfo(){
//do some file or db work.
}
Stream API Enhancement
❏ Jdk 9 added four new method for stream API.
❏ takeWhile().
❏ dropWhile().
❏ iterate().
❏ ofNullable().
Http/2 Client
❏ HTTP/1.1 is blocking mode, lot of performance issue and not supported HTTP2.
❏ HTTP/2 can send multiple request for data in parallel over a single TCP connection and
ASync mode.
❏ There are 3 new classes introduced to handle HTTP communication.
1) HttpClient (HttpClient handles the creation and send of requests.)
2) HttpRequest (HttpRequest is used to construct a request to be sent via the HttpClient.)
3) HttpResponse (HttpResponse holds the response from the request that has been sent.)
Q-> What does means of “incubator”?
Process API updates
❏ Two new interface has been added to JDK9, for providing more control over os
process.
❏ ProcessHandle
❏ ProcessHandle.Info
Example: ProcessHandle ph = ProcessHandle.current();
ph.getEveryThinh…..
Others Change
Compact String Enhancement->
Q-> What is the problem in existing String class ?
Q-> How String class engage our GC ? >>>Reference Link
Garbage Collector ->
G1 will be Default GC from JDK 9
Logging Updates ->
>>>Reference Link
Optional API Updated->
>>>Reference Link
Others Change
Array Utility ->
1)equals – returns true if two arrays are equal to each other.
2)compare – compares two arrays lexicographically (similar to dictionary order).
3)mismatch – finds and returns the index of the first mismatch between two arrays.
Reference Link
Stack-Walking API – Java 9->
Reference Link
Reactive Stream
❏ What is Reactive Programming ?
❏ Why Reactive Programming ?
❏ Reactive programming != Reactive system. (any confusion ?)
❏ The four Reactive principles
❏ JDK 9 Flow API.
❏ Non-blocking Back Pressure
❏ Reactive low level architecture.
❏ Callback Hell, How reactive solves the problem ?
❏ RXJava Implementation for java
Reactive Stream
❏ Java 9 includes a publish-subscribe framework for reactive streams.
❏ Flow is a repository for four nested static interfaces whose methods establish flow-
controlled components in which publishers produce data items that are consumed by one or
more subscribers:
❏ Publisher: A producer of data items that are received by subscribers.
❏ Subscriber: A receiver of data items.
❏ Subscription: Linkage between a Publisher and a Subscriber.
❏ Processor: A combination of Publisher and Subscriber for specifying a data-
transformation function.
Subscriber Interface
public static interface Subscriber<T> {
public void onSubscribe(Subscription subscription);
public void onNext(T item);
public void onError(Throwable throwable);
public void onComplete();
}
Let’s see all four concrete method impl
onSubscribe: invoked after a Publisher has completed the subscription for this
Subscriber (but before sending any Subscription item). The newly created
Subscription object is passed via this method. The Subscriber typically assigns this
instance to an instance variable for further use.
onNext: invoked with a Subscription's next item of type T.
onError: invoked upon an unrecoverable error encountered by a Publisher or
Subscription.
onComplete: invoked when no additional Subscriber method invocations will
occur including onNext() method.
Subscription Interface
❏ This is the key method behind non-blocking back-pressure concept. The
Subscriber uses it to request n more items for consumption. This way the
Subscriber controls how many items it is currently capable to receive (probably
it will want to limit the consumption according to what resources it has).
❏ Used by the Subscriber to cancel its subscription. After this call, no further
items will be received.
Publisher Interface
@FunctionalInterface
public static interface Publisher<T> {
public void subscribe(Subscriber<? super T> subscriber);1
}
❏ Used by the Subscribers for subscribing to receive the items of type T.
Processor Interface
A component that acts as both a Subscriber and Publisher.
public static interface Processor<T,R> extends Subscriber<T>, Publisher<R> {
}
SubmissionPublisher class
❏ This is the only concrete class provided in the Reactive Streams API. It
implements the Publisher interface. We can use its submit() method to publish
the provided item to each subscriber. In the following example we will see how
to use this class and at the same time we will get familiar with the usage of
above interfaces.
Reactive Stream (RXJAVA)
Reactivex.IO
Reference Link ->
http://openjdk.java.net/projects/jdk9/
https://blog.jetbrains.com/idea/2017/10/real-world-java-9/
https://www.youtube.com/watch?v=Yacu1yUktjY&t=7360s
https://blog.codefx.org/
https://zeroturnaround.com/rebellabs/java-9-modules-cheat-
sheet/
If you find any good article, please add over here…
Take Away->
Start using
Thank You :)

Weitere ähnliche Inhalte

Was ist angesagt?

Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionStephen Colebourne
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in JavaInnovationM
 
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughMahfuz Islam Bhuiyan
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemRafael Winterhalter
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introductionSagar Verma
 
02 Hibernate Introduction
02 Hibernate Introduction02 Hibernate Introduction
02 Hibernate IntroductionRanjan Kumar
 
Serialization in java
Serialization in javaSerialization in java
Serialization in javaJanu Jahnavi
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...Jorge Hidalgo
 
Design patterns in Java - Monitis 2017
Design patterns in Java - Monitis 2017Design patterns in Java - Monitis 2017
Design patterns in Java - Monitis 2017Arsen Gasparyan
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 javatwo2011
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Kernel Training
 

Was ist angesagt? (20)

Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
 
Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introduction
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in Java
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
Basic java for Android Developer
Basic java for Android DeveloperBasic java for Android Developer
Basic java for Android Developer
 
Java basic
Java basicJava basic
Java basic
 
Spring
SpringSpring
Spring
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introduction
 
02 Hibernate Introduction
02 Hibernate Introduction02 Hibernate Introduction
02 Hibernate Introduction
 
Serialization in java
Serialization in javaSerialization in java
Serialization in java
 
Java tips
Java tipsJava tips
Java tips
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
 
Java 7 & 8 New Features
Java 7 & 8 New FeaturesJava 7 & 8 New Features
Java 7 & 8 New Features
 
Design patterns in Java - Monitis 2017
Design patterns in Java - Monitis 2017Design patterns in Java - Monitis 2017
Design patterns in Java - Monitis 2017
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望
 
Complete Java Course
Complete Java CourseComplete Java Course
Complete Java Course
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
 

Ähnlich wie Java 9

Ähnlich wie Java 9 (20)

Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoop
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoop
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module System
 
Core java
Core java Core java
Core java
 
Core java &collections
Core java &collectionsCore java &collections
Core java &collections
 
Core java1
Core java1Core java1
Core java1
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 features
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
Insecure Java Deserialization
Insecure Java DeserializationInsecure Java Deserialization
Insecure Java Deserialization
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
java slides
java slidesjava slides
java slides
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
Letest
LetestLetest
Letest
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Java 9

  • 1. 9 New Features in Java 9 NETESH KUMAR
  • 2. Overview ❏ JSHELL ❏ JPMS (Java Platform Module System) ❏ JLINK ( Java Linker) ❏ HTTP2/Client ❏ Process API Updates ❏ Private Method Inside Interface ❏ Factory Method For Unmodifiable Collection ❏ Stream API, Try With Resource & Diamond Operator Enhancement ❏ Reactive Stream ❏ Others Change
  • 3. JShell (Java Shell) ❏ JShell is the read-eval-print-loop (REPL) tool used for interacting quickly with java from command line platform without the need to compile and run. ❏ Configure external editor with jshell.(/set editor “path” -w) ❏ Working with JAR/Module and file by setting classpath. (jshell --class-path “location”) ❏ It’s great for investigation of APIs that are unfamiliar to us. ❏ It’s wonderful for quick prototyping of tricky code. Like RegeX, Calculation based etc... ❏ Reference link: ❏ Link1 ❏ Link2
  • 4. JLink (Java Linker) ❏ Used for creating our own customize JRE ❏ Benefit: ❏ Smaller size of JAR. ❏ Suitable for IOT device and Microservices ❏ Running a simple JAR from anywhere even not required to pass “java” prefix.
  • 5. Change in Interface ❏ Until now (Java 8), we can have only default, static and abstract method inside interface. ❏ From Java 9, we can have private method as well. ❏ Benefit: ❏ To avoid redundant code and more reusability
  • 6. Immutable Collections ❏ Factory method for creating unmodifiable collections. ❏ Limitation: ❏ Can create only 0 to 10 size. ❏ But One method with varargs that let us create with desired number of element ❏ Benefit: ❏ Being shorter and nice to read ❏ List<String> string = List.of(“1” , ”2”); ❏ Set<Integer> set = Set.of(1,2); ❏ Map<Integer,Integer> map = Map.of(1,”a”,2,”b”); ❏ If we try to create with null element, a NullPointerException will be thrown. ❏ List<String> mutable = new ArrayList<>(List.of(“1”,”2”); mutable.add(null);
  • 7. try-with-resource Improvement ❏ Till Java 8 void readFile() throw IOException{ BufferedReader reader1 = new BufferedReader (new FileReader(“abc.txt”); try(BufferedReader reader2 =reader){ System.out.println(reader2.readLine()); } } ❏ Java 9 void readFile() throw IOException{ BufferedReader reader1 = new BufferedReader (new FileReader(“abc.txt”); try(reader1){ System.out.println(reader1.readLine()); } }
  • 8. Deprecated Enhancements ❏ Deprecated(since=”1.5” forRemoval=true) ❏ forRemoval: ❏ true means that “this API element is earmarked for removal in future release”If they don’t migrate away from the APU, their code could be break when new released is issued. ❏ false indicate that the API element is deprecated, but without any specific intent to remove that API in the future. ❏ The default value for this element is false. ❏ since: ❏ The String should contain the release or version number at which this API became deprecated. ❏ The default value of this element is empty string.
  • 9. JPMS (Java Platform Module System) ❏ What is JPMS ? ❏ Why we need JPMS ? ❏ How JPMS will solve existing problem ? Well know as Jigsaw project.
  • 10. What is JPMS ? ❏ The Java Platform Module System is a self-describing collection of Code, Data and some Resources. It is a set of related Packages, Types (classes, abstract classes, interfaces etc) with Code & Data and Resources. Any Confusion?
  • 11. ❏ If the idea of the module construct in java is simply to break code in small encapsulated unit,then we could do it before java 9. Question? ❏ Do you think, still we need Modularized JDK ? ❏ How will you control over class, package, jar etc...? ❏ What are the problem faced by developer in real life. ?
  • 12. Problem with JAR or ClassPath (JAR HELL) ❏ NoClassDefFoundError in middle of program execution. ❏ Version Conflict. ❏ Security threat . ❏ Bigger size, Unable to fit in IOT device and Microservices.
  • 13. Why JPMS ? ❏ Reliable configuration ❏ To provide better encapsulation, because public was too much public. ❏ To provide security ❏ Scalable java platform (in small memory we can run java application) ❏ Performance and Memory Improvement ❏ Question? What is special in java 9
  • 14. How JPMS will solve existing problem ? ❏ Whole JDK is modularized. ❏ All predefined java class are divided in 98 module. ❏ Module contains configuration information inside a file “module-info.java” ❏ System.out.println(String.class.getModule());
  • 15. Type of module ❏ There are three type of module. ❏ Named Module ❏ Unnamed module ❏ Automatic module
  • 16. Type of module ❏ Named module ❏ A named module is a module created with a module declaration file module-info.java in its root folder. module module_name { requires other_module_1; exports package_name_1; exports package_name to other_module; // qualified export opens some.client.package to framework.module; }
  • 17. Type of module ❏ Unnamed module ❏ Unnamed module is a jar built without module-info.java declaration. This means all current jars built in Java 8 and earlier releases are unnamed modules. ❏ JVM choose unnamed module name always. ❏ What modules it 'requires'? ● The unnamed module 'requires' every other named modules automatically. ● That means all classes within the unnamed module can read all other module (named or unnamed) without any explicit declaration of any kind. ● That also means that older classes (written prior to Java 9) can read all modules defined by the new Module system.
  • 18. Type of module ❏ Unnamed module ❏ What packages it 'exports'? ● The unnamed module 'exports' all its packages. ● That means different Jar applications which do not contain module or which are compiled in the older versions, will continue to use each other's dependencies as it is. ● The packages exported by unnamed module can only be read by another unnamed module. ❏ Do you have any question? Why unnamed module export all packages? ● This only ensure other unnamed modules can access its packages.
  • 19. Behind the scenes for Unnamed Module
  • 20. Unnamed module vs class path/module path ❏ Running using class path
  • 21. Unnamed module vs class path/module path ❏ Running using module path java --module-path out -module moduleName/com.netkumar.code.one.Unnamed What are you going to use moduleName above? We can’t run unnamed module name on module path. ❏ why don't we see all named modules of JSE 9 in above output. ● Java 9 import module on demand
  • 22. Using --describe-module ❏ --describe-module <module name> is a java command option,which describes a module details. ❏ jar command also has --describe-module option which does not require a module name. It describes the module in the specified jar.
  • 23. Summary ● The unnamed module does not have module-info.java. ● The unnamed module 'requires' all other modules and 'exports' all its packages. ● The classes which were written in the older versions but now running in Java 9 environment will continue to work because they become the members of the unnamed module. ● If we want to run old code in Java 9 environment without migrating them to the module system, we should run them using class path (not module path)
  • 24. Root Module Let’s understand root module first. What is 'requires transitive' ❏ Some modules which contain only module-info.java and no packages or no Java code. Their sole purpose is to require other modules (called root modules) and make them visible outside. 'java.se' is one of such module. ❏ 'requires transitive java.logging' will make java.logging available to the module which requires java.se module. ❏ requires transitive == export or requires transitive != export ? what do you think about this ? ● 'exports' is used to make packages visible, ● 'requires transitive' is used to make imported modules visible outside.
  • 25. Root Module How root modules are used? ❏ When the Unnamed Module is being compiled or loaded, one of the set of root modules should be accessible to the Unnamed module (so that a non-modular application will continue to work).
  • 26. Type of module What if a named module wants to read the existing jars or third party jar built without module-info.java created? Automatic module ❏ Java will create module from jar files automatically. These module are called Automatica module. ❏ The only thing you need to do is to put the jar file in the module path instead of the class path. ❏ Once a jar without module-info is put in the module path, it becomes an automatic module automatically. ❏ An automatic module can read all other modules and all other modules can read it as well. Even the named modules can read an automatic module. ❏ How automatic module will have a module name derived from its jar name? Do we have any rule ?
  • 27. Automatic module Rules: ● It drop the jar file extension ● It replace - character with . ● It remove the version string What packages it 'exports'? ❏ It 'exports' all its packages. What modules it 'requires'? ❏ It 'requires' all other modules on the module path.
  • 30. Live coding for below scenario ❏ Compatibility and Migration ❏ Split Packages ❏ Module Modes ❏ Modules and Services ❏ Qualified Exports ❏ Reflective Access CLI Compilation: (Note:- share cheat sheet) Javac --module-source-path “give module source path ” -d “where you want to create out dir” “all java file or module name” Java --module-path “out” --add-module “module name” “give main class”
  • 31. Diamond operator ->Anonymous Inner class❏ We can create <> operator for anonymous inner classes from JDK9. Example: List<String> list = new ArrayList<String>(){ { add(“one”); add(“two”); } }
  • 32. SafeVarargs Enhancement ❏ We can apply @safevarargs annotation on private method from jdk9. Example: @safeVarargs private static String getInfo(){ //do some file or db work. }
  • 33. Stream API Enhancement ❏ Jdk 9 added four new method for stream API. ❏ takeWhile(). ❏ dropWhile(). ❏ iterate(). ❏ ofNullable().
  • 34. Http/2 Client ❏ HTTP/1.1 is blocking mode, lot of performance issue and not supported HTTP2. ❏ HTTP/2 can send multiple request for data in parallel over a single TCP connection and ASync mode. ❏ There are 3 new classes introduced to handle HTTP communication. 1) HttpClient (HttpClient handles the creation and send of requests.) 2) HttpRequest (HttpRequest is used to construct a request to be sent via the HttpClient.) 3) HttpResponse (HttpResponse holds the response from the request that has been sent.) Q-> What does means of “incubator”?
  • 35. Process API updates ❏ Two new interface has been added to JDK9, for providing more control over os process. ❏ ProcessHandle ❏ ProcessHandle.Info Example: ProcessHandle ph = ProcessHandle.current(); ph.getEveryThinh…..
  • 36. Others Change Compact String Enhancement-> Q-> What is the problem in existing String class ? Q-> How String class engage our GC ? >>>Reference Link Garbage Collector -> G1 will be Default GC from JDK 9 Logging Updates -> >>>Reference Link Optional API Updated-> >>>Reference Link
  • 37. Others Change Array Utility -> 1)equals – returns true if two arrays are equal to each other. 2)compare – compares two arrays lexicographically (similar to dictionary order). 3)mismatch – finds and returns the index of the first mismatch between two arrays. Reference Link Stack-Walking API – Java 9-> Reference Link
  • 38. Reactive Stream ❏ What is Reactive Programming ? ❏ Why Reactive Programming ? ❏ Reactive programming != Reactive system. (any confusion ?) ❏ The four Reactive principles ❏ JDK 9 Flow API. ❏ Non-blocking Back Pressure ❏ Reactive low level architecture. ❏ Callback Hell, How reactive solves the problem ? ❏ RXJava Implementation for java
  • 39. Reactive Stream ❏ Java 9 includes a publish-subscribe framework for reactive streams. ❏ Flow is a repository for four nested static interfaces whose methods establish flow- controlled components in which publishers produce data items that are consumed by one or more subscribers: ❏ Publisher: A producer of data items that are received by subscribers. ❏ Subscriber: A receiver of data items. ❏ Subscription: Linkage between a Publisher and a Subscriber. ❏ Processor: A combination of Publisher and Subscriber for specifying a data- transformation function.
  • 40. Subscriber Interface public static interface Subscriber<T> { public void onSubscribe(Subscription subscription); public void onNext(T item); public void onError(Throwable throwable); public void onComplete(); }
  • 41. Let’s see all four concrete method impl onSubscribe: invoked after a Publisher has completed the subscription for this Subscriber (but before sending any Subscription item). The newly created Subscription object is passed via this method. The Subscriber typically assigns this instance to an instance variable for further use. onNext: invoked with a Subscription's next item of type T. onError: invoked upon an unrecoverable error encountered by a Publisher or Subscription. onComplete: invoked when no additional Subscriber method invocations will occur including onNext() method.
  • 42. Subscription Interface ❏ This is the key method behind non-blocking back-pressure concept. The Subscriber uses it to request n more items for consumption. This way the Subscriber controls how many items it is currently capable to receive (probably it will want to limit the consumption according to what resources it has). ❏ Used by the Subscriber to cancel its subscription. After this call, no further items will be received.
  • 43. Publisher Interface @FunctionalInterface public static interface Publisher<T> { public void subscribe(Subscriber<? super T> subscriber);1 } ❏ Used by the Subscribers for subscribing to receive the items of type T.
  • 44. Processor Interface A component that acts as both a Subscriber and Publisher. public static interface Processor<T,R> extends Subscriber<T>, Publisher<R> { }
  • 45. SubmissionPublisher class ❏ This is the only concrete class provided in the Reactive Streams API. It implements the Publisher interface. We can use its submit() method to publish the provided item to each subscriber. In the following example we will see how to use this class and at the same time we will get familiar with the usage of above interfaces.