5. Java in Numbers
• #1 Development Platform in the world
• 9 Millions Developers
• 800.000 Java Certifications
• 7 Billion devices run Java
• 1 Billion Java Downloads per Year
• 97% of Enterprise Desktops run Java
• 100% of Blu-ray Disc Players ship with Java
16. Jigsaw
JEP 220: Modular Run-Time Images
JEP 201: Modular Source Code
JEP 260: Encapsulate Most Internal
APIs
JEP 282: jlink: The Java Linker
JEP 162: Prepare for Modularization
JSR 376: Java Platform Module System JEP 200: The Modular JDK
JEP 261: Module System
Modularity
Java Module
17. Why Modularity: Problem with Java 8
• Java Runtime getting bigger and bigger.
– Java 8 compact profile 1, 2 and 3 is the partial solution of Modularity.
• Jar and classpath hell.
– Hard to determine if anything missing.
– Hard to find internal conflict.
– Lazy class loading and initialization – NoClassDefFoundError.
• For code that escapes packages the visibility mechanism is poor - only
public.
– Classes from different packages “see” each other, even from different class loaders
– SecurityManager helps to protect, but it is not on by default
34. Module
module = A container of packages
Module can exports specific package to all
Module can exports specific package to specific module
Module can import other module
37. Modular Security
Accessibility (Java 9)
• public
– public to everyone
– public, but only to specific modules
– public only within a module
• protected
• default
• private
public ≠ accessible (fundamental change to Java)
50. What is jshell?
• Tool providing a dynamic interaction with the Java™ programming
language
• Read-Evaluate-Print Loop (REPL) for the Java™ platform
– Type in a snippet of Java code, see the results
• Deeply integrated with JDK tool-set
– Stays current and compatible
• Also, an API for use within other applications
51. What jshell is “Not”?
• Not a new language
– “Snippets” of pure
• No new syntax
• Not a replacement for the compiler
• Not an IDE (Integrated Development Environment)
52. Who wants jshell?
• New to Java, new to programming
– Start with expressions vs classes
– Immediate feedback
• Exploring a new API or language feature
– Experiment and instantly see results
• Prototyping
– Incrementally write complex code
53. Without jshell: Edit Compile Run
• Write a full program:
– Class
– Imports
– main method
• Cycle the whole program to understand if the behavior is
correct:
– Edit
– Compiler or IDE
– Execute
54. Without jshell: Edit Compile Run
> edit Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
> javac Hello.java
> java Hello
………….. Repeat
55. With jshell
>jshell
| Welcome to JShell -- Version 9-ea
| For an introduction type: /help intro
jshell> System.out.println("Hello World")
Hello World
58. New Collection API
• Java Collection is verbose.
• Ruby Collection:
list = [1, 2, 3]
set = Set.new [1, 2, 3]
map = { ‘a’=> 1, ‘b’ => 2, ‘c’ => 3}
• Java Collection:
List<Integer> list = Arrays.asList(1, 2, 3);
Set<Integer> set = new HashSet<>(Arrays.asList(1, 2, 3));
Map<String, Integer> map = new HashMap<>();
map.put(“a”,1);
map.put(“b”,2);
map.put(“c”,3);
59. New Collection API
• Java Collection is verbose.
• Python Collection:
list = [1, 2, 3]
set = {1, 2, 3}
map = { ‘a’ : 1, ‘b’ : 2, ‘c’ : 3}
• Java Collection:
List<Integer> list = Arrays.asList(1, 2, 3);
Set<Integer> set = new HashSet<>(Arrays.asList(1, 2, 3));
Map<String, Integer> map = new HashMap<>();
map.put(“a”,1);
map.put(“b”,2);
map.put(“c”,3);
60. New Collection API
List<Integer> list = Arrays.asList(1, 2, 3);
Set<Integer> set = new HashSet<>(Arrays.asList(1, 2, 3));
Map<String, Integer> map = new HashMap<>();
map.put(“a”,1);
map.put(“b”,2);
map.put(“c”,3);
List<Integer> list = List.of(1, 2, 3);
Set<Integer> set = Set.of(1, 2, 3);
Map<String, Integer> map = Map.ofEntries(entry(“a”,1), entry(“b”,2), entry(“c”,3));
61. G1 : New Garbage collector
• Now GC is the default garbage collector.
• In JDK 9, the G1 the default garbage collector.
• Many performance improvements were made to G1 in JDK 8 and its update
releases, and further improvements are planned for JDK 9.
• The introduction of concurrent class unloading (JEP 156) in JDK 8u40 made G1 a
fully-featured garbage collector, ready to be the default.
62. HTML 5 and Javadoc Search
• Enhance the javadoc tool to generate HTML5 markup.
• Add a search box to generated API documentation that can be used to search for program elements and
tagged words and phrases within the documentation.
63. Deprecate the Applet API
Add the @Deprecated(since="9") annotation to the following classes:
• java.applet.AppletStub
• java.applet.Applet
• java.applet.AudioClip
• java.applet.AppletContext
• javax.swing.JApplet
64. Process API Update
• JEP 102: Process API Updates
• New:
– Get PID number from JVM
– Get list of processes
– Operations on tree of processes
65. Process API Update
Process proc = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c",
"echo $PPID"});
if (proc.waitFor() == 0) {
InputStream in = proc.getInputStream();
int available = in.available();
byte[] outputBytes = new byte[available];
in.read(outputBytes);
String pid = new String(outputBytes);
System.out.println("Your pid is " + pid);
}
System.out.println("Your pid is " + ProcessHandle.current().getPid());
66. Summary
• Modularisation is a big change for Java
– JVM/JRE rather than language/APIs
– Public access isn’t necessarily the same
• Flexibility to define what is exported
• New linking capability to generate runtime image
• More to learn about converting existing code
• Will make all applications simpler to deploy and manage