SlideShare a Scribd company logo
Ali BAKAN

Software Engineer



28.09.2018

ali.bakan@cloudnesil.com

https://cloudnesil.com
WHAT IS NEW IN JAVA 10
1
WHAT IS NEW IN JAVA 10
Java 10 contains various new features and enhancements.
This is the fastest release of a java version in its 23 year
history :)
1. New Features in Language
2. New Features in Compiler
3. New Features in Libraries
4. New Features in Tools
5. New Features in Runtime
6. Miscellaneous Changes
2
WHAT IS NEW IN JAVA 10
1. NEW FEATURES IN LANGUAGE
1. Local variable type inference
2. Time-Based Release Versioning
3. Root Certificates
3
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE
1.1 LOCAL VARIABLE TYPE INFERENCE
‣ Java is known to be a bit verbose, which can be good when it comes to
understanding what you or another developer had in mind when a function was
written. Local variable type inference feature breaks this rule.
‣ Local variable type inference is the biggest new feature in Java 10 for developers.
‣ With the exception of assert from the Java 1.4 days, new keywords always seem
to make a big splash, and var is no different.
‣ What the var keyword does is turn local variable assignments:



Map<String, String> myMap = new HashMap<>();



into:



var thisIsAlsoMyMap = new HashMap<String, String>();
4
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE
1.1 LOCAL VARIABLE TYPE INFERENCE
‣ Local type inference can be used only in the following
scenarios:
- Limited only to local variable with initializer
- Indexes of enhanced for loop or indexes
- Local declared in for loop
‣ It cannot be used for member variables, method parameters,
return types, etc.
‣ var is not a keyword – this ensures backward compatibility for
programs using var as a function or variable name.
5
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE
1.1 LOCAL VARIABLE TYPE INFERENCE
‣ We can’t use ‘var’ in scenarios below:
- var n; // cannot use 'var' without initializer
- var emptyList = null; // variable initializer is ‘null'
- public var = "hello"; // 'var' is not allowed here
- var p = (String s) -> s.length() > 10; // lambda expression
needs an explicit target-type
- var arr = { 1, 2, 3 }; // array initializer needs an explicit
target-type
6
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE
1.1 LOCAL VARIABLE TYPE INFERENCE
‣ Example:



var numbers = List.of(1, 2, 3, 4, 5); // inferred value ArrayList<String>



// Index of Enhanced For Loop

for (var number : numbers) {

System.out.println(number);

}



// Local variable declared in a loop

for (var i = 0; i < numbers.size(); i++) {

System.out.println(numbers.get(i));

}
7
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE
1.2 TIME-BASED RELEASE VERSIONING
‣ The development of new Java versions was, up until now,
very feature driven.
‣ This meant that you had to wait for a few years for the next
release.
‣ Oracle has now switched to a new, time based model.
‣ Not everyone agrees with this proceeding. Larger
companies also appreciated the stability and the low rate
of change of Java so far
8
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE
1.2 TIME-BASED RELEASE VERSIONING
‣ Oracle has responded to these concerns and continues to
offer long-term releases on a regular basis, but also at
longer intervals. And after Java 8, it is Java 11, which will
receive a long term support again.
‣ Java 9 and Java 10 on the other hand will only be
supported for the time period of half a year, until the next
release is due.
‣ In fact, Java 9 and Java 10 support has just ended, since
Java 11 is out.
9
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE
1.2 TIME-BASED RELEASE VERSIONING
‣ With adoption of time based release cycle, Oracle changed the version-string
scheme of the Java SE Platform and the JDK, and related versioning
information, for present and future time-based release models
‣ The new pattern of the Version number is: FEATURE.INTERIM.UPDATE.PATCH
‣ FEATURE: counter will be incremented every 6 months and will be based on
feature release versions, e.g: JDK 10, JDK 11.
‣ INTERIM: counter will be incremented for non-feature releases that contain
compatible bug fixes and enhancements but no incompatible changes.
‣ UPDATE: counter will be incremented for compatible update releases that fix
security issues, regressions, and bugs in newer features.
‣ PATCH: counter will be incremented for an emergency release to fix a critical
issue.
10
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE
1.3 ROOT CERTIFICATES
‣ The cacerts keystore, which was initially empty so far, is
intended to contain a set of root certificates that can be used to
establish trust in the certificate chains used by various security
protocols.
‣ With Java 10, Oracle has open-sourced the root certificates in
Oracle’s Java SE Root CA program in order to make OpenJDK
builds more attractive to developers and to reduce the
differences between those builds and Oracle JDK builds.
‣ Basically, this means that now doing simple things like
communicating over HTTPS between your application and, say,
a Google RESTful service will be much simpler with OpenJDK.
11
WHAT IS NEW IN JAVA 10
2. NEW FEATURES IN COMPILER
1. Experimental Java-Based JIT Compiler
2. Bytecode Generation for Enhanced for Loop
12
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN COMPILER
2.1 EXPERIMENTAL JAVA-BASED JIT COMPILER
‣ The Just-In-Time (JIT) Compiler is the part of java that converts java
byte code into machine code at runtime. It was written in c++
‣ This feature enables the Java-based JIT compiler, Graal, to be used as
an experimental JIT compiler on the Linux/x64 platform.
‣ Graal is a complete rewrite of the JIT compiler in java from scratch.
‣ To enable Graal, add these flags to your command line arguments
when starting the application:



-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler
‣ Keep in mind that the Graal team makes no promises in this first release
that this compiler is any faster.
13
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN COMPILER
2.2 BYTE CODE GENERATION FOR ENHANCED FOR LOOP
‣ Bytecode generation has been improved for enhanced for loops, providing
an improvement in the translation approach for them. For example:



List<String> data = new ArrayList<>(); for (String b : data);



The following is the code generated after the enhancement:



{ /*synthetic*/ Iterator i$ = data.iterator(); for (; i$.hasNext(); ) { String b =
(String)i$.next(); } b = null; i$ = null; }
‣ Declaring the iterator variable outside of the for loop allows a null to be
assigned to it as soon as it is no longer used
‣ This makes it accessible to the GC, which can then get rid of the unused
memory.
14
WHAT IS NEW IN JAVA 10
3. NEW FEATURES IN LIBRARIES
1. Creating Unmodifiable Collections
2. Optional.orElseThrow() Method
15
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LIBRARIES
3.1 CREATING UNMODIFIABLE COLLECTIONS
1. Several new APIs have been added that facilitate the creation of unmodifiable
collections.
2. The List.copyOf, Set.copyOf, and Map.copyOf methods create new collection
instances from existing instances.
3. New methods toUnmodifiableList, toUnmodifiableSet, and
toUnmodifiableMap have been added to the Collectors class in the stream
package. These methods allow the elements of a Stream to be collected into
an unmodifiable collection.



Stream<String> myStream = Stream.of("a", "b", "c");

List<String> unModifiableList =
myStream.collect(Collectors.toUnmodifiableList());

unModifiableList.add(“d"); // throws java.lang.UnsupportedOperationException
16
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LIBRARIES
3.2 CREATING UNMODIFIABLE COLLECTIONS
‣ Optional, OptionalDouble, OptionalInt and OptionalLong each
got a new method orElseThrow() which doesn’t take any argument
and throws NoSuchElementException if no value is present: 



@Test

public void whenListContainsInteger_OrElseThrowReturnsInteger() {

Integer firstEven = someIntList.stream()

.filter(i -> i % 2 == 0)

.findFirst()

.orElseThrow();

is(firstEven).equals(Integer.valueOf(2));

}
17
WHAT IS NEW IN JAVA 10
4. NEW FEATURES IN TOOLS
1. JShell Startup
2. Removed Tools
18
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN TOOLS
4.1 JSHELL STARTUP
‣ The time needed to start JShell has been significantly
reduced, especially in cases where a start file with many
snippets is used
19
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN TOOLS
4.2 REMOVED TOOLS
‣ Tool javah has been removed from Java 10 which
generated C headers and source files which were required
to implement native methods. Now, javac -h can be used
instead.
‣ policytool was the security tool for policy file creation and
management. This has now been removed.
20
WHAT IS NEW IN JAVA 10
5. NEW FEATURES IN RUNTIME
1. Parallel Full GC for G1
2. Improvements for Docker Containers
3. Application Data-Class Sharing
4. Removed Options
21
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME
5.1. PARALLEL FULL GC FOR G1
‣ G1 garbage collector was made default in JDK 9.
‣ However, the full GC for G1 used a single threaded mark-sweep-
compact algorithm.
‣ This has been changed to the parallel mark-sweep-compact algorithm
in Java 10 effectively reducing the stop-the-world time during full GC.
‣ This change won’t help the best-case performance times of the
garbage collector, but it does significantly reduce the worst-case
latencies.
‣ When concurrent garbage collection falls behind, it triggers a Full GC
collection.
22
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME
5.2. IMPROVEMENTS FOR DOCKER CONTAINERS
‣ The JVM now knows when it is running inside a Docker
Container.
‣ This means the application now has accurate information
about what the docker container allocates to memory,
CPU, and other system resources.
‣ Previously, the JVM queried the host operating system to
get this information.
‣ However, this support is only available for Linux-based
platforms.
23
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME
5.2. IMPROVEMENTS FOR DOCKER CONTAINERS
‣ There are command line options to specify how the JVM inside a Docker container allocates
internal memory.
‣ This new support is enabled by default and can be disabled in the command line with the
JVM option:



-XX:-UseContainerSupport
‣ To set the memory heap to the container group size and limit the number of processors you
could pass in these arguments:



-XX:+UseCGroupMemoryLimitForHeap -XX:ActiveProcessorCount=2
‣ Three new JVM options have been added to allow Docker container users to gain more fine-
grained control over the amount of system memory that will be used for the Java Heap:



-XX:InitialRAMPercentage

-XX:MaxRAMPercentage

-XX:MinRAMPercentage
24
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME
5.3. APPLICATION DATA-CLASS SHARING
‣ Java 5 introduced Class-Data Sharing (CDS) to improve startup times of
smaller Java applications.
‣ CDS only allowed the bootstrap class loader, limiting the feature to system
classes only.
‣ This feature extends the existing CDS feature for allowing application classes
to be placed in the shared archive in order to improve startup and footprint.
‣ The general idea was that when the JVM first launched, anything loaded was
serialized and stored in a file on disk that could be reloaded on future
launches of the JVM.
‣ This meant that multiple instances of the JVM shared the class metadata so it
wouldn’t have to load them all every time.
25
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME
5.3. APPLICATION DATA-CLASS SHARING
‣ We can use the following steps to make use of this feature:
1. Get the list of classes to archive:

$ java -Xshare:off -XX:+UseAppCDS 

-XX:DumpLoadedClassList=hello.lst -cp hello.jar HelloWorld
2. Create the AppCDS archive:

$ java -Xshare:dump -XX:+UseAppCDS 

-XX:SharedClassListFile=hello.lst 

-XX:SharedArchiveFile=hello.jsa -cp hello.jar
3. Use the AppCDS archive:

$ java -Xshare:on -XX:+UseAppCDS 

-XX:SharedArchiveFile=hello.jsa -cp hello.jar HelloWorld
26
WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME
5.4. REMOVED OPTIONS
‣ Removal of FlatProfiler: The FlatProfiler, deprecated in
JDK 9, has been made obsolete by removing the
implementation code. The FlatProfiler was enabled by
setting the -Xprof VM argument. The -Xprof flag remains
recognized in this release; however, setting it will print out
a warning message
‣ Removal of Obsolete -X Options: The obsolete HotSpot
VM options (-Xoss, -Xsqnopause, -Xoptimize, -
Xboundthreads, and -Xusealtsigs) have been removed
27
WHAT IS NEW IN JAVA 10
6. MISCELLANEOUS CHANGES
‣ Class File Version Number is 54.0:

The class file version has been changed from 53 (or 44 + 9) to 54 (44 +10), even though
JDK 10 did not introduce other changes to the class file format.
‣ Consolidate the JDK Forest into a Single Repository:

Combined the numerous repositories of the JDK forest into a single repository to
simplify and streamline development. The code base until now has been broken into
multiple repos, which can cause problems with source-code management.
‣ Additional Unicode Language-Tag Extensions:

Enhanced the java.util.Locale and related APIs to implement additional Unicode
extensions of BCP 47 language tags.
‣ Garbage Collector Interface:

A clean garbage collector interface to improve source-code isolation of different
garbage collectors. The goals for this effort include better modularity for internal
garbage collection code in the HotSpot virtual machine and making it easier to add a
new garbage collector to HotSpot.
28
WHAT IS NEW IN JAVA 10
6. MISCELLANEOUS CHANGES
‣ Heap Allocation on Alternative Memory Devices:

It enables the HotSpot VM to allocate the Java object heap
on an alternative memory device, such as an NV-DIMM,
specified by the user.
‣ Thread-Local Handshakes

This is an internal JVM feature to improve performance.
This feature provides a way to execute a callback on
threads without performing a global VM safepoint. Make it
both possible and cheap to stop individual threads and
not just all threads or none.
29
WHAT IS NEW IN JAVA 10
SOURCES
- https://www.oracle.com/technetwork/java/javase/10-
relnote-issues-4108729.html
- http://cr.openjdk.java.net/~iris/se/10/latestSpec/
- https://www.baeldung.com/java-10-overview
- https://stackify.com/whats-new-in-java-10/
- https://www.journaldev.com/20395/java-10-features
- https://www.quora.com/What-is-new-in-Java-10
30

More Related Content

What's hot (20)

PDF
Deep Dive Java 17 Devoxx UK
José Paumard
 
PDF
Lambda Expressions in Java
Erhan Bagdemir
 
PDF
Intrinsic Methods in HotSpot VM
Kris Mok
 
PDF
Java 8 lambda expressions
Logan Chien
 
PDF
Java modules
Rory Preddy
 
PDF
Spring boot introduction
Rasheed Waraich
 
PDF
Graal and Truffle: One VM to Rule Them All
Thomas Wuerthinger
 
PPTX
Migrating to Java 11
Arto Santala
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
PDF
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Edureka!
 
PPTX
UseNUMA做了什么?(2012-03-14)
Kris Mok
 
PPTX
Lambda Expressions in Java 8
icarter09
 
PDF
Spring Boot & Actuators
VMware Tanzu
 
PPTX
Spring boot
Gyanendra Yadav
 
PPTX
Functional programming with Java 8
LivePerson
 
PDF
Spring boot
Bhagwat Kumar
 
PPTX
Basics of Java Concurrency
kshanth2101
 
PPTX
Core java
Shivaraj R
 
PDF
Introducing Drools
Mario Fusco
 
PPTX
Core java
Ravi varma
 
Deep Dive Java 17 Devoxx UK
José Paumard
 
Lambda Expressions in Java
Erhan Bagdemir
 
Intrinsic Methods in HotSpot VM
Kris Mok
 
Java 8 lambda expressions
Logan Chien
 
Java modules
Rory Preddy
 
Spring boot introduction
Rasheed Waraich
 
Graal and Truffle: One VM to Rule Them All
Thomas Wuerthinger
 
Migrating to Java 11
Arto Santala
 
Spring boot Introduction
Jeevesh Pandey
 
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Edureka!
 
UseNUMA做了什么?(2012-03-14)
Kris Mok
 
Lambda Expressions in Java 8
icarter09
 
Spring Boot & Actuators
VMware Tanzu
 
Spring boot
Gyanendra Yadav
 
Functional programming with Java 8
LivePerson
 
Spring boot
Bhagwat Kumar
 
Basics of Java Concurrency
kshanth2101
 
Core java
Shivaraj R
 
Introducing Drools
Mario Fusco
 
Core java
Ravi varma
 

Similar to Java 10 New Features (20)

PPTX
java new technology
chavdagirimal
 
PPTX
[JOI] TOTVS Developers Joinville - Java #1
Rubens Dos Santos Filho
 
PPT
Features java9
srmohan06
 
PDF
Java 9-coding-from-zero-level-v1.0
Parikshit Kumar Singh
 
PDF
What is new in node 8
OnGraph Technologies Pvt. Ltd.
 
PPTX
Follow these reasons to know java’s importance
nishajj
 
PDF
The features of java 11 vs. java 12
FarjanaAhmed3
 
PPT
Java7
Dinesh Guntha
 
PDF
Angular 11 – everything you need to know
WebGuru Infosystems Pvt. Ltd.
 
PDF
How easy (or hard) it is to monitor your graph ql service performance
Red Hat
 
PDF
Top Features And Updates Of Angular 13 You Must Know
Andolasoft Inc
 
PDF
Java 9 and Beyond
Mayank Patel
 
PDF
Microsoft .NET 6 -What's All About The New Update
Adam John
 
PDF
What's Expected in Java 7
Gal Marder
 
PPTX
Classes and Objects
Prabu U
 
PPT
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
Srijan Technologies
 
PDF
What angular 13 will bring to the table
Moon Technolabs Pvt. Ltd.
 
PDF
Brief introduction to Angular 2.0 & 4.0
Nisheed Jagadish
 
PDF
Angular version 10 is here check out the new features, notable changes, depr...
Katy Slemon
 
PDF
Fabric8 - Being devOps doesn't suck anymore
Henryk Konsek
 
java new technology
chavdagirimal
 
[JOI] TOTVS Developers Joinville - Java #1
Rubens Dos Santos Filho
 
Features java9
srmohan06
 
Java 9-coding-from-zero-level-v1.0
Parikshit Kumar Singh
 
What is new in node 8
OnGraph Technologies Pvt. Ltd.
 
Follow these reasons to know java’s importance
nishajj
 
The features of java 11 vs. java 12
FarjanaAhmed3
 
Angular 11 – everything you need to know
WebGuru Infosystems Pvt. Ltd.
 
How easy (or hard) it is to monitor your graph ql service performance
Red Hat
 
Top Features And Updates Of Angular 13 You Must Know
Andolasoft Inc
 
Java 9 and Beyond
Mayank Patel
 
Microsoft .NET 6 -What's All About The New Update
Adam John
 
What's Expected in Java 7
Gal Marder
 
Classes and Objects
Prabu U
 
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
Srijan Technologies
 
What angular 13 will bring to the table
Moon Technolabs Pvt. Ltd.
 
Brief introduction to Angular 2.0 & 4.0
Nisheed Jagadish
 
Angular version 10 is here check out the new features, notable changes, depr...
Katy Slemon
 
Fabric8 - Being devOps doesn't suck anymore
Henryk Konsek
 
Ad

Recently uploaded (20)

PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Ad

Java 10 New Features

  • 2. WHAT IS NEW IN JAVA 10 Java 10 contains various new features and enhancements. This is the fastest release of a java version in its 23 year history :) 1. New Features in Language 2. New Features in Compiler 3. New Features in Libraries 4. New Features in Tools 5. New Features in Runtime 6. Miscellaneous Changes 2
  • 3. WHAT IS NEW IN JAVA 10 1. NEW FEATURES IN LANGUAGE 1. Local variable type inference 2. Time-Based Release Versioning 3. Root Certificates 3
  • 4. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE 1.1 LOCAL VARIABLE TYPE INFERENCE ‣ Java is known to be a bit verbose, which can be good when it comes to understanding what you or another developer had in mind when a function was written. Local variable type inference feature breaks this rule. ‣ Local variable type inference is the biggest new feature in Java 10 for developers. ‣ With the exception of assert from the Java 1.4 days, new keywords always seem to make a big splash, and var is no different. ‣ What the var keyword does is turn local variable assignments:
 
 Map<String, String> myMap = new HashMap<>();
 
 into:
 
 var thisIsAlsoMyMap = new HashMap<String, String>(); 4
  • 5. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE 1.1 LOCAL VARIABLE TYPE INFERENCE ‣ Local type inference can be used only in the following scenarios: - Limited only to local variable with initializer - Indexes of enhanced for loop or indexes - Local declared in for loop ‣ It cannot be used for member variables, method parameters, return types, etc. ‣ var is not a keyword – this ensures backward compatibility for programs using var as a function or variable name. 5
  • 6. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE 1.1 LOCAL VARIABLE TYPE INFERENCE ‣ We can’t use ‘var’ in scenarios below: - var n; // cannot use 'var' without initializer - var emptyList = null; // variable initializer is ‘null' - public var = "hello"; // 'var' is not allowed here - var p = (String s) -> s.length() > 10; // lambda expression needs an explicit target-type - var arr = { 1, 2, 3 }; // array initializer needs an explicit target-type 6
  • 7. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE 1.1 LOCAL VARIABLE TYPE INFERENCE ‣ Example:
 
 var numbers = List.of(1, 2, 3, 4, 5); // inferred value ArrayList<String>
 
 // Index of Enhanced For Loop
 for (var number : numbers) {
 System.out.println(number);
 }
 
 // Local variable declared in a loop
 for (var i = 0; i < numbers.size(); i++) {
 System.out.println(numbers.get(i));
 } 7
  • 8. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE 1.2 TIME-BASED RELEASE VERSIONING ‣ The development of new Java versions was, up until now, very feature driven. ‣ This meant that you had to wait for a few years for the next release. ‣ Oracle has now switched to a new, time based model. ‣ Not everyone agrees with this proceeding. Larger companies also appreciated the stability and the low rate of change of Java so far 8
  • 9. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE 1.2 TIME-BASED RELEASE VERSIONING ‣ Oracle has responded to these concerns and continues to offer long-term releases on a regular basis, but also at longer intervals. And after Java 8, it is Java 11, which will receive a long term support again. ‣ Java 9 and Java 10 on the other hand will only be supported for the time period of half a year, until the next release is due. ‣ In fact, Java 9 and Java 10 support has just ended, since Java 11 is out. 9
  • 10. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE 1.2 TIME-BASED RELEASE VERSIONING ‣ With adoption of time based release cycle, Oracle changed the version-string scheme of the Java SE Platform and the JDK, and related versioning information, for present and future time-based release models ‣ The new pattern of the Version number is: FEATURE.INTERIM.UPDATE.PATCH ‣ FEATURE: counter will be incremented every 6 months and will be based on feature release versions, e.g: JDK 10, JDK 11. ‣ INTERIM: counter will be incremented for non-feature releases that contain compatible bug fixes and enhancements but no incompatible changes. ‣ UPDATE: counter will be incremented for compatible update releases that fix security issues, regressions, and bugs in newer features. ‣ PATCH: counter will be incremented for an emergency release to fix a critical issue. 10
  • 11. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LANGUAGE 1.3 ROOT CERTIFICATES ‣ The cacerts keystore, which was initially empty so far, is intended to contain a set of root certificates that can be used to establish trust in the certificate chains used by various security protocols. ‣ With Java 10, Oracle has open-sourced the root certificates in Oracle’s Java SE Root CA program in order to make OpenJDK builds more attractive to developers and to reduce the differences between those builds and Oracle JDK builds. ‣ Basically, this means that now doing simple things like communicating over HTTPS between your application and, say, a Google RESTful service will be much simpler with OpenJDK. 11
  • 12. WHAT IS NEW IN JAVA 10 2. NEW FEATURES IN COMPILER 1. Experimental Java-Based JIT Compiler 2. Bytecode Generation for Enhanced for Loop 12
  • 13. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN COMPILER 2.1 EXPERIMENTAL JAVA-BASED JIT COMPILER ‣ The Just-In-Time (JIT) Compiler is the part of java that converts java byte code into machine code at runtime. It was written in c++ ‣ This feature enables the Java-based JIT compiler, Graal, to be used as an experimental JIT compiler on the Linux/x64 platform. ‣ Graal is a complete rewrite of the JIT compiler in java from scratch. ‣ To enable Graal, add these flags to your command line arguments when starting the application:
 
 -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler ‣ Keep in mind that the Graal team makes no promises in this first release that this compiler is any faster. 13
  • 14. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN COMPILER 2.2 BYTE CODE GENERATION FOR ENHANCED FOR LOOP ‣ Bytecode generation has been improved for enhanced for loops, providing an improvement in the translation approach for them. For example:
 
 List<String> data = new ArrayList<>(); for (String b : data);
 
 The following is the code generated after the enhancement:
 
 { /*synthetic*/ Iterator i$ = data.iterator(); for (; i$.hasNext(); ) { String b = (String)i$.next(); } b = null; i$ = null; } ‣ Declaring the iterator variable outside of the for loop allows a null to be assigned to it as soon as it is no longer used ‣ This makes it accessible to the GC, which can then get rid of the unused memory. 14
  • 15. WHAT IS NEW IN JAVA 10 3. NEW FEATURES IN LIBRARIES 1. Creating Unmodifiable Collections 2. Optional.orElseThrow() Method 15
  • 16. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LIBRARIES 3.1 CREATING UNMODIFIABLE COLLECTIONS 1. Several new APIs have been added that facilitate the creation of unmodifiable collections. 2. The List.copyOf, Set.copyOf, and Map.copyOf methods create new collection instances from existing instances. 3. New methods toUnmodifiableList, toUnmodifiableSet, and toUnmodifiableMap have been added to the Collectors class in the stream package. These methods allow the elements of a Stream to be collected into an unmodifiable collection.
 
 Stream<String> myStream = Stream.of("a", "b", "c");
 List<String> unModifiableList = myStream.collect(Collectors.toUnmodifiableList());
 unModifiableList.add(“d"); // throws java.lang.UnsupportedOperationException 16
  • 17. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN LIBRARIES 3.2 CREATING UNMODIFIABLE COLLECTIONS ‣ Optional, OptionalDouble, OptionalInt and OptionalLong each got a new method orElseThrow() which doesn’t take any argument and throws NoSuchElementException if no value is present: 
 
 @Test
 public void whenListContainsInteger_OrElseThrowReturnsInteger() {
 Integer firstEven = someIntList.stream()
 .filter(i -> i % 2 == 0)
 .findFirst()
 .orElseThrow();
 is(firstEven).equals(Integer.valueOf(2));
 } 17
  • 18. WHAT IS NEW IN JAVA 10 4. NEW FEATURES IN TOOLS 1. JShell Startup 2. Removed Tools 18
  • 19. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN TOOLS 4.1 JSHELL STARTUP ‣ The time needed to start JShell has been significantly reduced, especially in cases where a start file with many snippets is used 19
  • 20. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN TOOLS 4.2 REMOVED TOOLS ‣ Tool javah has been removed from Java 10 which generated C headers and source files which were required to implement native methods. Now, javac -h can be used instead. ‣ policytool was the security tool for policy file creation and management. This has now been removed. 20
  • 21. WHAT IS NEW IN JAVA 10 5. NEW FEATURES IN RUNTIME 1. Parallel Full GC for G1 2. Improvements for Docker Containers 3. Application Data-Class Sharing 4. Removed Options 21
  • 22. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME 5.1. PARALLEL FULL GC FOR G1 ‣ G1 garbage collector was made default in JDK 9. ‣ However, the full GC for G1 used a single threaded mark-sweep- compact algorithm. ‣ This has been changed to the parallel mark-sweep-compact algorithm in Java 10 effectively reducing the stop-the-world time during full GC. ‣ This change won’t help the best-case performance times of the garbage collector, but it does significantly reduce the worst-case latencies. ‣ When concurrent garbage collection falls behind, it triggers a Full GC collection. 22
  • 23. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME 5.2. IMPROVEMENTS FOR DOCKER CONTAINERS ‣ The JVM now knows when it is running inside a Docker Container. ‣ This means the application now has accurate information about what the docker container allocates to memory, CPU, and other system resources. ‣ Previously, the JVM queried the host operating system to get this information. ‣ However, this support is only available for Linux-based platforms. 23
  • 24. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME 5.2. IMPROVEMENTS FOR DOCKER CONTAINERS ‣ There are command line options to specify how the JVM inside a Docker container allocates internal memory. ‣ This new support is enabled by default and can be disabled in the command line with the JVM option:
 
 -XX:-UseContainerSupport ‣ To set the memory heap to the container group size and limit the number of processors you could pass in these arguments:
 
 -XX:+UseCGroupMemoryLimitForHeap -XX:ActiveProcessorCount=2 ‣ Three new JVM options have been added to allow Docker container users to gain more fine- grained control over the amount of system memory that will be used for the Java Heap:
 
 -XX:InitialRAMPercentage
 -XX:MaxRAMPercentage
 -XX:MinRAMPercentage 24
  • 25. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME 5.3. APPLICATION DATA-CLASS SHARING ‣ Java 5 introduced Class-Data Sharing (CDS) to improve startup times of smaller Java applications. ‣ CDS only allowed the bootstrap class loader, limiting the feature to system classes only. ‣ This feature extends the existing CDS feature for allowing application classes to be placed in the shared archive in order to improve startup and footprint. ‣ The general idea was that when the JVM first launched, anything loaded was serialized and stored in a file on disk that could be reloaded on future launches of the JVM. ‣ This meant that multiple instances of the JVM shared the class metadata so it wouldn’t have to load them all every time. 25
  • 26. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME 5.3. APPLICATION DATA-CLASS SHARING ‣ We can use the following steps to make use of this feature: 1. Get the list of classes to archive:
 $ java -Xshare:off -XX:+UseAppCDS 
 -XX:DumpLoadedClassList=hello.lst -cp hello.jar HelloWorld 2. Create the AppCDS archive:
 $ java -Xshare:dump -XX:+UseAppCDS 
 -XX:SharedClassListFile=hello.lst 
 -XX:SharedArchiveFile=hello.jsa -cp hello.jar 3. Use the AppCDS archive:
 $ java -Xshare:on -XX:+UseAppCDS 
 -XX:SharedArchiveFile=hello.jsa -cp hello.jar HelloWorld 26
  • 27. WHAT IS NEW IN JAVA 10 - NEW FEATURES IN RUNTIME 5.4. REMOVED OPTIONS ‣ Removal of FlatProfiler: The FlatProfiler, deprecated in JDK 9, has been made obsolete by removing the implementation code. The FlatProfiler was enabled by setting the -Xprof VM argument. The -Xprof flag remains recognized in this release; however, setting it will print out a warning message ‣ Removal of Obsolete -X Options: The obsolete HotSpot VM options (-Xoss, -Xsqnopause, -Xoptimize, - Xboundthreads, and -Xusealtsigs) have been removed 27
  • 28. WHAT IS NEW IN JAVA 10 6. MISCELLANEOUS CHANGES ‣ Class File Version Number is 54.0:
 The class file version has been changed from 53 (or 44 + 9) to 54 (44 +10), even though JDK 10 did not introduce other changes to the class file format. ‣ Consolidate the JDK Forest into a Single Repository:
 Combined the numerous repositories of the JDK forest into a single repository to simplify and streamline development. The code base until now has been broken into multiple repos, which can cause problems with source-code management. ‣ Additional Unicode Language-Tag Extensions:
 Enhanced the java.util.Locale and related APIs to implement additional Unicode extensions of BCP 47 language tags. ‣ Garbage Collector Interface:
 A clean garbage collector interface to improve source-code isolation of different garbage collectors. The goals for this effort include better modularity for internal garbage collection code in the HotSpot virtual machine and making it easier to add a new garbage collector to HotSpot. 28
  • 29. WHAT IS NEW IN JAVA 10 6. MISCELLANEOUS CHANGES ‣ Heap Allocation on Alternative Memory Devices:
 It enables the HotSpot VM to allocate the Java object heap on an alternative memory device, such as an NV-DIMM, specified by the user. ‣ Thread-Local Handshakes
 This is an internal JVM feature to improve performance. This feature provides a way to execute a callback on threads without performing a global VM safepoint. Make it both possible and cheap to stop individual threads and not just all threads or none. 29
  • 30. WHAT IS NEW IN JAVA 10 SOURCES - https://www.oracle.com/technetwork/java/javase/10- relnote-issues-4108729.html - http://cr.openjdk.java.net/~iris/se/10/latestSpec/ - https://www.baeldung.com/java-10-overview - https://stackify.com/whats-new-in-java-10/ - https://www.journaldev.com/20395/java-10-features - https://www.quora.com/What-is-new-in-Java-10 30