SlideShare una empresa de Scribd logo
1 de 60
Descargar para leer sin conexión
Java & Beyond
Java 9
Mohammad Hossein Rimaz
K. N. Toosi University of Technology
KNTU Java User Group
Outline:
•JShell
•Modularity
•Other Java 9 Features
•Road Ahead
JShell
What?
• JShell is a REPL (Read-Evaluate-Print Loop), a command line
tool which allows developer to coding in java without
building projects in IDEs or compiling and running their short
code which is quite lengthy task
• If you are familiar with interpreted language like Python or
other JVM languages like Groovy or Scala the concept of
JShell is familiar to you.
Why?
• Good for new programmers and beginners
• Good for testing language features
JShell Commands:
• /list [all]
• /vars, /methods, /classes
• /edit
• /reset
• /set editor [notepad, gedit, …]
• /imports
• /exit
• /env [add module, classpath, …]
• /save, /open [mysession.jsh]
DEMO
Web Scraping with JSOUP and JShell
Modularity
Outline:
•What? & Why?
•How?
•Details
•Transitive Dependency
•Aggregator Module
•Services
•JDeps
What? & Why?
• Java 9 was delayed so many times because of Project Jigsaw.
• You might have been hearing a lot about modules,
modularity, and other stuff.
• What it’s all about?
• What the heck is modularization and what do we mean by a
modularized platform?
• What's the Java Platform Module System (JPMS) all about?
• Is it going to be a revolution in Java ecosystem?
What? & Why?
• Maintainability is one of the most significant concerns in
software design and evolution.
• We want a code base that is loosely coupled, highly cohesive,
extremely readable, and can be understandable at a glance.
• We design our classes and organize them in packages.
• When we have hundreds of packages, the dependencies
between them are not visible at one look.
• We need something more than packages to organize our
code base to make it more maintainable.
What? & Why?
• Another problem is the Java classpath and how it runs our
codes.
• All JAR classes and libraries are flattened into the classpath.
When these JAR files have multiple version of a class on the
runtime, the Java ClassLoader can load only one version of
that class. In this way, there is ambiguity about how your
program is going to work, and ambiguity is a bad thing. This
issue is so frequent that you might know it as “JAR Hell.”
• Inefficient, Insecure, and even Dangerous!
What? & Why?
• Another problem with the classpath is that it doesn’t follow
the “Fail First” principle.
• You may have missing classes that exist in the classpath, but
not in the production environment. Until you get
the JavaClassDefError exception at runtime, you can’t be
sure what is missing.
What? & Why?
• Finally, the big issue with the classpath is encapsulation.
Every class on the classpath has access to each other, and
this is an encapsulation violation.
• We want to hide our internal APIs, and that’s why we need
another level of encapsulation (“Strong Encapsulation”) and
control over the access to our classes in our packages.
Uses of JDK Internal APIs:
Taken from: https://www.slideshare.net/haochenglee/prepare-for-jdk-9
Uses of JDK Internal APIs:
What? & Why?
• Modules are going to fix these issues.
• What is a module? A module has a name, it groups related
code, and is self-contained.
• A module describes explicitly what it needs from other
modules and which part of it is visible to other modules.
What? & Why?
• In this manner, dependencies between modules are crystal
clear.
• We have Strong Encapsulation, which means we can hide
our internal APIs, and finally
• We now follow the “Fail First” principle. Therefore, when
there is a missing module or a conflict, you will get an error.
What? & Why?
• Modularizing the JDK allows JDK developers to manage the
huge complexity of it.
• When you write a tiny and straightforward application that
doesn’t use RMI, CORBA, Java EE, and other stuff, why do
you need a full, huge, and heavy JRE?
• Isn’t it wiser to have your runtime image only contain the
modules you need?
• Now with a modularized platform, it’s possible.
• Modularizing the JDK allows JDK developers to manage the
huge complexity of it.
• When you write a tiny and straightforward application that
doesn’t use RMI, CORBA, Java EE, and other stuff, why do
you need a full, huge, and heavy JRE?
• Isn’t it wiser to have your runtime image only contain the
modules you need?
• Now with a modularized platform, it’s possible.
What? & Why?
What? & Why?
• This is how the JDK now looks.
• On the bottom, we have the “java.base” module that every
other module implicitly or explicitly depends on.
• As you can see, this dependency graph is a DAG, which
means no circular dependencies allowed [at compile-time!].
What? & Why?
What? & Why?
Review
•Strong Encapsulation.
•Handling Complexity through Modularization.
•Fail-First: No JAR HELL, No Conflict, No
ClassDefFoundError Exception.
•Custom Runtime Images, Smaller Footprint,
Better Performance.
How?
• The picture shows
essentially what a
module is.
• Each module has a
module descriptor called
“module-info.java.”
How?
• In the module-info.java
file, you describe the
name of your module,
what it requires to work,
and which packages are
visible outside this
module.
• So in its simplest form,
the module-info.java
looks like this image:
How?
Commands
• java --list-modules
List of JDK’s modules
How?
Commands
• java --describe-module
Show module’s
descriptor
DEMO
Create Our First Modular Application
Using Command-Line
How?
Create Our First Modular Application Using Command-Line
• Project Structure
How?
Create Our First Modular Application Using Command-Line
• Compiling
javac --module-source-
path src -d out
srckntujug.hellomodulei
rackntuHelloWorld.java
srckntujug.hellomodule
module-info.java
How?
Create Our First Modular Application Using Command-Line
• Running
java --module-path out -m
kntujug.hellomodule/ir.ac.kntu.HelloWorld
-> Hello World
How?
Create Our First Modular Application Using Command-Line
• Create Custom Runtime Image
jlink --module-path
"%JAVA_HOME%jmods;out" --add-modules
kntujug.hellomodule --output runtimeimage
How?
Create Our First Modular Application Using Command-Line
How?
Create Our First Modular Application Using Command-Line
$ runtimeimagebinjava --describe-module kntujug.hellomodule
kntujug.hellomodule
requires java.base mandated
contains ir.ac.kntu
$ runtimeimagebinjava --module kntujug.hellomodule/ir.ac.kntu.HelloWorld
Hello World
$ runtimeimagebinjava --list-modules
java.base@9.0.1
kntujug.hellomodule
DEMO
AdoptOpenJDK/Session1/01,02,03,04,05
https://github.com/AdoptOpenJDK/jdk9-jigsaw
Details
Transitive Dependency
java.sql
java.xml
java.logging
Application
Requires Transitive
Requires Transitive
Requires
Details
Transitive Dependency
Details
Naming
• For Application Modules
• Short & memorable names
• Example: applicationname.modulename
• For Library Developer
• Global Uniqueness
• Reverse DNS
• Example: ir.ac.kntu.applicationname.modulename
Details
Aggregator Module
java.se
java.logging
java.sqlApplication
java.desktop
Requires Transitive
Requires Transitive
Requires
Details
Aggregator Module
Details
Aggregator Module
Details
Services
• Suppose we have an application that requests to all online
taxi services and request the cheapest taxi service.
chipsi.napsi chipsi.tapsi chipsi.maxsi
chipsi.taxifinder
Details
Services
chipsi.napsi chipsi.tapsi chipsi.maxsi
chipsi.taxifinder
chipsi.discovery
module chipsi.taxifinder{
requires chipsi.discovery;
requires chipsi.maxsi;
requires chipsi.tapsi;
requires chipsi.napsi;
}
DEMO
Show Chipsi Modular Application
Details
Services
• All of these approaches are wrong.
• Two known approach
• Factory Pattern : Still we should know about implementations
name.
• Dependency Injection
• But we can use Services and ServiceLoader
Details
Services
chipsi.napsi chipsi.tapsi chipsi.maxsi
chipsi.taxifinder
chipsi.discovery
module chipsi.taxifinder{
uses chipsi.discovery.Service;
}
module chipsi.discovery{
exports chipsi.discovery;
}
module chipsi.napsi{
provides chipsi.discovery.Service with
com.napsi.NapsiServiceProvider;
}
DEMO
Show Chipsi Modular Application
Using Services and ServiceLoader
Details
• And so many advance features like
• Optional Dependencies
• Add Modules at Runtime
• Resource Encapsulation
• ServiceLoader Life Cycle
• Auto Modules
• Unnamed Modules
• You can refer to the provided references to learn about
them.
Other
Features
Other New Features
•Collections Factory
•HTTP/2, WebSocket, HTTP/1.1
•Stream API Improvements
•Reactive Streams with Flow API
•StackWalker
Other New Features
•JavaFX Enhancement and new APIs
•G1 Garbage Collector as Default GC
•Multi-Release JAR Files [JEP-238]
•Enhanced Deprecation
•HTML5 JavaDoc
•And so many other features and enhancements
…
DEMO
Async HTTP Request
Road Ahead
Resources
• Java 9 Modularity
Patterns and Practices for
developing maintainable
applications
By Sander Mak & Paul Bakker
• Many examples and
descriptions of this slides taken
from this book
Resources
• Java 9 Recipes
A Problem-Solution Approach
By Josh Juneau
• A General Book about Java 9
Resources
• Java 9 Modularity Revealed
Project Jigsaw and Scalable
Java Applications
By Alexandru Jecan
• Yet another in depth java 9
modularity book.
JavaOne 2017 Talks:
• Modules in One Lesson
by Mark Reinhold
• Migration to Modules
by Mark Reinhold
• Modules and Services
by Alex Buckley
• Designing for Modularity with Java 9
by Sander Mak and Paul Bakker
Hands On Code:
Work with this GitHub repository.
https://github.com/AdoptOpenJDK/jdk9-jigsaw
Q&A
Thanks for
Your
Attendance

Más contenido relacionado

La actualidad más candente

Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introductionSagar Verma
 
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 studentsPartnered Health
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platformsIlio Catallo
 
Java Tutorial to Learn Java Programming
Java Tutorial to Learn Java ProgrammingJava Tutorial to Learn Java Programming
Java Tutorial to Learn Java Programmingbusiness Corporate
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Nayden Gochev
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014Nayden Gochev
 
SoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringSoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringNayden Gochev
 
Java introduction
Java introductionJava introduction
Java introductionSagar Verma
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javajayc8586
 
Top 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersTop 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersWhizlabs
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel StreamTengwen Wang
 
Modern Java Concurrency
Modern Java ConcurrencyModern Java Concurrency
Modern Java ConcurrencyBen Evans
 
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Edureka!
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machineLaxman Puri
 

La actualidad más candente (20)

Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introduction
 
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 and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
 
Java Tutorial to Learn Java Programming
Java Tutorial to Learn Java ProgrammingJava Tutorial to Learn Java Programming
Java Tutorial to Learn Java Programming
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
Java 8 parallel stream
Java 8 parallel streamJava 8 parallel stream
Java 8 parallel stream
 
History of java
History of javaHistory of java
History of java
 
SoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringSoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with Spring
 
Java introduction
Java introductionJava introduction
Java introduction
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Top 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersTop 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed Answers
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel Stream
 
Core Java
Core JavaCore Java
Core Java
 
Modern Java Concurrency
Modern Java ConcurrencyModern Java Concurrency
Modern Java Concurrency
 
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 

Destacado

Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in JavaErhan Bagdemir
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeNikita Lipsky
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadDavid Gómez García
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.David Gómez García
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsNewCircle Training
 
The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)Robert Scholte
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9Trisha Gee
 

Destacado (10)

Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Parallel streams in java 8
Parallel streams in java 8Parallel streams in java 8
Parallel streams in java 8
 
The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 

Similar a Java 9, JShell, and Modularity

Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan Cuprak
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Mihail Stoynov
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)David Bosschaert
 
Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Adam Mokan
 
Leaner microservices with Java 10
Leaner microservices with Java 10Leaner microservices with Java 10
Leaner microservices with Java 10Arto Santala
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG sessionMani Sarkar
 
Java 9 / Jigsaw - LJC / VJUG session (hackday session)
Java 9 / Jigsaw - LJC / VJUG session (hackday session)Java 9 / Jigsaw - LJC / VJUG session (hackday session)
Java 9 / Jigsaw - LJC / VJUG session (hackday session)Mani Sarkar
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java LanguagePawanMM
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
Developing modular Java applications
Developing modular Java applicationsDeveloping modular Java applications
Developing modular Java applicationsJulien Dubois
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using MavenScheidt & Bachmann
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...SQALab
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updatesVinay H G
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
 

Similar a Java 9, JShell, and Modularity (20)

Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)
 
Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012
 
Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
Leaner microservices with Java 10
Leaner microservices with Java 10Leaner microservices with Java 10
Leaner microservices with Java 10
 
Stackato v6
Stackato v6Stackato v6
Stackato v6
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG session
 
Java modules
Java modulesJava modules
Java modules
 
Java 9 / Jigsaw - LJC / VJUG session (hackday session)
Java 9 / Jigsaw - LJC / VJUG session (hackday session)Java 9 / Jigsaw - LJC / VJUG session (hackday session)
Java 9 / Jigsaw - LJC / VJUG session (hackday session)
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java Language
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Developing modular Java applications
Developing modular Java applicationsDeveloping modular Java applications
Developing modular Java applications
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...
 
Stackato v5
Stackato v5Stackato v5
Stackato v5
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 

Más de Mohammad Hossein Rimaz

Más de Mohammad Hossein Rimaz (7)

004 - JavaFX Tutorial - Event Handling
004 - JavaFX Tutorial - Event Handling004 - JavaFX Tutorial - Event Handling
004 - JavaFX Tutorial - Event Handling
 
003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts
 
002- JavaFX Tutorial - Getting Started
002- JavaFX Tutorial - Getting Started002- JavaFX Tutorial - Getting Started
002- JavaFX Tutorial - Getting Started
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Continuous integration with Jenkins
Continuous integration with JenkinsContinuous integration with Jenkins
Continuous integration with Jenkins
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 

Último

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Java 9, JShell, and Modularity

  • 1. Java & Beyond Java 9 Mohammad Hossein Rimaz K. N. Toosi University of Technology KNTU Java User Group
  • 4. What? • JShell is a REPL (Read-Evaluate-Print Loop), a command line tool which allows developer to coding in java without building projects in IDEs or compiling and running their short code which is quite lengthy task • If you are familiar with interpreted language like Python or other JVM languages like Groovy or Scala the concept of JShell is familiar to you.
  • 5. Why? • Good for new programmers and beginners • Good for testing language features
  • 6. JShell Commands: • /list [all] • /vars, /methods, /classes • /edit • /reset • /set editor [notepad, gedit, …] • /imports • /exit • /env [add module, classpath, …] • /save, /open [mysession.jsh]
  • 7. DEMO Web Scraping with JSOUP and JShell
  • 9. Outline: •What? & Why? •How? •Details •Transitive Dependency •Aggregator Module •Services •JDeps
  • 10. What? & Why? • Java 9 was delayed so many times because of Project Jigsaw. • You might have been hearing a lot about modules, modularity, and other stuff. • What it’s all about? • What the heck is modularization and what do we mean by a modularized platform? • What's the Java Platform Module System (JPMS) all about? • Is it going to be a revolution in Java ecosystem?
  • 11. What? & Why? • Maintainability is one of the most significant concerns in software design and evolution. • We want a code base that is loosely coupled, highly cohesive, extremely readable, and can be understandable at a glance. • We design our classes and organize them in packages. • When we have hundreds of packages, the dependencies between them are not visible at one look. • We need something more than packages to organize our code base to make it more maintainable.
  • 12. What? & Why? • Another problem is the Java classpath and how it runs our codes. • All JAR classes and libraries are flattened into the classpath. When these JAR files have multiple version of a class on the runtime, the Java ClassLoader can load only one version of that class. In this way, there is ambiguity about how your program is going to work, and ambiguity is a bad thing. This issue is so frequent that you might know it as “JAR Hell.” • Inefficient, Insecure, and even Dangerous!
  • 13. What? & Why? • Another problem with the classpath is that it doesn’t follow the “Fail First” principle. • You may have missing classes that exist in the classpath, but not in the production environment. Until you get the JavaClassDefError exception at runtime, you can’t be sure what is missing.
  • 14. What? & Why? • Finally, the big issue with the classpath is encapsulation. Every class on the classpath has access to each other, and this is an encapsulation violation. • We want to hide our internal APIs, and that’s why we need another level of encapsulation (“Strong Encapsulation”) and control over the access to our classes in our packages.
  • 15. Uses of JDK Internal APIs: Taken from: https://www.slideshare.net/haochenglee/prepare-for-jdk-9
  • 16. Uses of JDK Internal APIs:
  • 17. What? & Why? • Modules are going to fix these issues. • What is a module? A module has a name, it groups related code, and is self-contained. • A module describes explicitly what it needs from other modules and which part of it is visible to other modules.
  • 18. What? & Why? • In this manner, dependencies between modules are crystal clear. • We have Strong Encapsulation, which means we can hide our internal APIs, and finally • We now follow the “Fail First” principle. Therefore, when there is a missing module or a conflict, you will get an error.
  • 19. What? & Why? • Modularizing the JDK allows JDK developers to manage the huge complexity of it. • When you write a tiny and straightforward application that doesn’t use RMI, CORBA, Java EE, and other stuff, why do you need a full, huge, and heavy JRE? • Isn’t it wiser to have your runtime image only contain the modules you need? • Now with a modularized platform, it’s possible.
  • 20. • Modularizing the JDK allows JDK developers to manage the huge complexity of it. • When you write a tiny and straightforward application that doesn’t use RMI, CORBA, Java EE, and other stuff, why do you need a full, huge, and heavy JRE? • Isn’t it wiser to have your runtime image only contain the modules you need? • Now with a modularized platform, it’s possible. What? & Why?
  • 21. What? & Why? • This is how the JDK now looks. • On the bottom, we have the “java.base” module that every other module implicitly or explicitly depends on. • As you can see, this dependency graph is a DAG, which means no circular dependencies allowed [at compile-time!].
  • 23. What? & Why? Review •Strong Encapsulation. •Handling Complexity through Modularization. •Fail-First: No JAR HELL, No Conflict, No ClassDefFoundError Exception. •Custom Runtime Images, Smaller Footprint, Better Performance.
  • 24. How? • The picture shows essentially what a module is. • Each module has a module descriptor called “module-info.java.”
  • 25. How? • In the module-info.java file, you describe the name of your module, what it requires to work, and which packages are visible outside this module. • So in its simplest form, the module-info.java looks like this image:
  • 28. DEMO Create Our First Modular Application Using Command-Line
  • 29. How? Create Our First Modular Application Using Command-Line • Project Structure
  • 30. How? Create Our First Modular Application Using Command-Line • Compiling javac --module-source- path src -d out srckntujug.hellomodulei rackntuHelloWorld.java srckntujug.hellomodule module-info.java
  • 31. How? Create Our First Modular Application Using Command-Line • Running java --module-path out -m kntujug.hellomodule/ir.ac.kntu.HelloWorld -> Hello World
  • 32. How? Create Our First Modular Application Using Command-Line • Create Custom Runtime Image jlink --module-path "%JAVA_HOME%jmods;out" --add-modules kntujug.hellomodule --output runtimeimage
  • 33. How? Create Our First Modular Application Using Command-Line
  • 34. How? Create Our First Modular Application Using Command-Line $ runtimeimagebinjava --describe-module kntujug.hellomodule kntujug.hellomodule requires java.base mandated contains ir.ac.kntu $ runtimeimagebinjava --module kntujug.hellomodule/ir.ac.kntu.HelloWorld Hello World $ runtimeimagebinjava --list-modules java.base@9.0.1 kntujug.hellomodule
  • 38. Details Naming • For Application Modules • Short & memorable names • Example: applicationname.modulename • For Library Developer • Global Uniqueness • Reverse DNS • Example: ir.ac.kntu.applicationname.modulename
  • 42. Details Services • Suppose we have an application that requests to all online taxi services and request the cheapest taxi service. chipsi.napsi chipsi.tapsi chipsi.maxsi chipsi.taxifinder
  • 43. Details Services chipsi.napsi chipsi.tapsi chipsi.maxsi chipsi.taxifinder chipsi.discovery module chipsi.taxifinder{ requires chipsi.discovery; requires chipsi.maxsi; requires chipsi.tapsi; requires chipsi.napsi; }
  • 45. Details Services • All of these approaches are wrong. • Two known approach • Factory Pattern : Still we should know about implementations name. • Dependency Injection • But we can use Services and ServiceLoader
  • 46. Details Services chipsi.napsi chipsi.tapsi chipsi.maxsi chipsi.taxifinder chipsi.discovery module chipsi.taxifinder{ uses chipsi.discovery.Service; } module chipsi.discovery{ exports chipsi.discovery; } module chipsi.napsi{ provides chipsi.discovery.Service with com.napsi.NapsiServiceProvider; }
  • 47. DEMO Show Chipsi Modular Application Using Services and ServiceLoader
  • 48. Details • And so many advance features like • Optional Dependencies • Add Modules at Runtime • Resource Encapsulation • ServiceLoader Life Cycle • Auto Modules • Unnamed Modules • You can refer to the provided references to learn about them.
  • 50. Other New Features •Collections Factory •HTTP/2, WebSocket, HTTP/1.1 •Stream API Improvements •Reactive Streams with Flow API •StackWalker
  • 51. Other New Features •JavaFX Enhancement and new APIs •G1 Garbage Collector as Default GC •Multi-Release JAR Files [JEP-238] •Enhanced Deprecation •HTML5 JavaDoc •And so many other features and enhancements …
  • 54. Resources • Java 9 Modularity Patterns and Practices for developing maintainable applications By Sander Mak & Paul Bakker • Many examples and descriptions of this slides taken from this book
  • 55. Resources • Java 9 Recipes A Problem-Solution Approach By Josh Juneau • A General Book about Java 9
  • 56. Resources • Java 9 Modularity Revealed Project Jigsaw and Scalable Java Applications By Alexandru Jecan • Yet another in depth java 9 modularity book.
  • 57. JavaOne 2017 Talks: • Modules in One Lesson by Mark Reinhold • Migration to Modules by Mark Reinhold • Modules and Services by Alex Buckley • Designing for Modularity with Java 9 by Sander Mak and Paul Bakker
  • 58. Hands On Code: Work with this GitHub repository. https://github.com/AdoptOpenJDK/jdk9-jigsaw
  • 59. Q&A