SlideShare une entreprise Scribd logo
1  sur  27
Java 8 - New Features
NaveenHegde
Apr 2014
Java Version History
2
1996 1998 2000 2002 2004 2006 2011
Java SE 8
Spider
2014
First release developed
under the Java
Community Process
Version 1.5 -> 5
To reflect level of
Maturity, Stability
J2SE -> Java SE
Dropped .0
• Java 5
– Generics, Autoboxing
– Enhanced For-Loop, VarArgs and more…
Recap - Major Feature Additions in
Java
3
 Java 6
• Script Engine
• New I/O
• Jconsole, profiler & debug interface (JVMPI, JVMDI)
 Java 7
• Strings in Switch, Catch Multiple-Exceptions
• Try-with-Resource, Type Interface
• JVM Support for Non-Java Languages
• Lambda Expressions
• Streams Facility
• Date-Time Library
• permgen replaced by Metaspace
• Type Annotations and Repeating Annotations
• jdbc-odbc bridge removed
• New utilities to improve Performance, Scalability
Java SE 8 New Features at glance
4
• Treat functionality as method argument (code as data)
• Avoid anonymous inner class which seem excessive & unclear
• Cleaner way to implement Functional Interfaces
• Used to create anonymous methods
Lambda Expressions
5
Parameter(s)
Body
single expression or statement block
Lambda Expression Syntax
Sample Code for “Sorting persons array by Age”
Java compiler determines Lambda Expr Type using new “Target Typing” mechanism
• In Swing, JavaFX, Often, event handler interfaces are
functional interfaces
• Lambda expressions can best replace anonymous classes
created for keyboard actions, mouse actions etc
Using Lambda Expression in GUI
6
• Creation of compact, easy-to-read lambda expressions
• Use it with Lambda Expresions for
– Encapsulate a single unit of behavior and pass it to other code
– Create simple instance of a functional interface
Method References
7
Method Reference Type Example
to a static method Person::compareByAge
to an instance method of a particular object myComparator::compareByName
to a method of arbitrary type instance String::compareToIgnoreCase
to a constructor HashSet::new
• Ability to add default implementation in interfaces
• No impact on already existing implementations
Default Interface Method
8
 Extending Interfaces That Contain Default Methods
• Not mention default method -> inherits the default
• Redeclare the default method -> makes it abstract.
• Redefine the default method -> overrides it
Interface with all default methods is like an Adapter
• New package for filter/map/reduce transformations on streams
• Includes many useful built in aggregate operations
java.util.stream.*
9
int ave = Arrays.stream(personArr)
.filter(b -> b.getGender() == Gender.MALE)
.mapToDouble(Person::getSalary)
.average()
.getAsDouble();
‘persons’ is a Collection<Person>
 Generating Streams
• Collection objects: via the stream() and parallelStream() methods
• Array elements: via Arrays.stream(Object[])
• Lines of File : BufferedReader.lines()
• Streams of random numbers : Random.ints()
• No storage
– A stream is not a data structure that stores elements
– it conveys elements from a source (Array,Collection,IO Channel
etc) through a pipeline of computational operations
– stream operation produces a result without modifing its source
• Functional in nature
– Enable Functional way of Working with Databases – Easy and elegant
• Parallelism
– Streams facilitate parallel execution by reframing the computation as a
pipeline of aggregate operations
• Consumable
– The elements are visited only once during the life of a stream.
– new stream must be generated to revisit the same elements
Why use Streams?
10
• JavaSE 6
– Date
– Calendar
– DateFormat
– TimeZone
Date-Time Packages
11
 Java 8
formatter=DateTimeFormatter.ofPattern("yyyy MM dd");
String text = date.toString(formatter);
LocalDate date = LocalDate.parse(text, formatter)
ChronoUnit.DAYS.between(t1, t2)
• Motive
– Solve the common scalability problem of “Maintaining a single count, sum,
etc. that is updated by many threads”
• How?
– Internally employ contention-reduction techniques
– Provides huge throughput improvements as compared to Atomic variables
• Classes
– DoubleAccumulator
 One or more variables that together maintain a running double value updated using a
supplied function.
– DoubleAdder
 One or more variables that together maintain an initially zero double sum.
– LongAccumulator
– LongAdder
Scalable-Updatable variable support
12
• Streams & Lambda expression based new methods
– forEach methods
 forEach, forEachKey, forEachValue, and forEachEntry
– search methods
 search, searchKeys, searchValues, and searchEntries
– reduction methods
 reduce, reduceToDouble, reduceToLong …
ConcurrentHashMap Enhancements
13
-> ConcurrentHashMaps (and classes built from them) are more useful as cache
• Interfaces
– CompletionStage<T>: A stage of a possibly asynchronous computation
• Classes
– CompletableFuture<T>: A Future that may be explicitly completed
 May be used as a CompletionStage,
 Supports actions that trigger upon its completion
– CountedCompleter<T>: A ForkJoinTask with a completion Action
 Action is triggered when there are no remaining pending actions
– ConcurrentHashMap.KeySetView<K,V>:
 A view of ConcurrentHashMap as a Set of keys
 Additions may optionally be enabled by mapping to a common value
New Additions to java.util.concurrent
14
• Arrays.parallelSort()
– Parallel merge-sort algorithm technique using ForkJoinPool
• Bulk Data Operations for Collections
• Base64 Encoding & Decoding support
– New Classes
 Base64, Base64.Decoder, Base64.Encoder
– Eg Applications of use
 Multipurpose Internet Mail Extensions (MIME)
 encode passwords for HTTP headers
Utils
15
• StampedLock
– A capability-based lock with three modes for controlling access
 1) Reading 2) Writing 3) Optimistic Reading
– Lock acquisition methods return a stamp
– Stamp represents and controls access with respect to a lock state
– Designed for the development of thread-safe components
– Not re-entrant
• ForkJoinPool (since java7)
– ExecutorService for running ForkJoinTasks
– A static commonPool() is added to reduce resource usage
 Default pool appropriate for most applications
– ForkJoinPool differs from other kinds of ExecutorService
 Mainly by virtue of employing work-stealing
 All threads in the pool attempt to find and execute subtasks created by other tasks or external
clients like management and monitoring operations
Miscellaneous
16
• Repeating Annotations
– provide the ability to apply the same annotation type more than once to
the same declaration
• Type Annotations
– provide the ability to apply an annotation anywhere a type is used, not
just on a declaration.
– Used with a pluggable type system,
– this feature enables improved type checking of your code
Annotations
17
• Motive
– Eliminate need for ‘MaxPermSize’ tuning (one of the reasons for OOM error)
– Improve GC performance
• Removal of PermGen
– Most allocations for the class metadata is done out of native memory
– Some miscellaneous data has been moved to the Java heap
– klasses that were used to described class metadata have been removed
– Metaspace is Non-contigeous to heap
– A garbage collection may be induced to collect dead classloaders and classes. The
first garbage collection will be induced when the class metadata usage reaches
MaxMetaspaceSize
PermGen replaced by Metaspace
18
Heap
NewGen
Survivor Space
OldGen
PermGen
Heap
NewGen
Survivor Space
OldGen
Metaspace Native
Mem
PermGen=Region{
Class Metadata, Hierarchy info,
Constant Pool, Bytecode …}
No more “OutOfMemoryError:
PermGen space”
• Defines subsets of JRE for devices that have limited
storage capacity
• Match Application Functional needs closely
Compact Profiles
19
Security(E) JMX Instrumentation XML JAXP (E)
JDBC RMI XML JAXP
Core Networking IO Collections
Scripting Regex JNDI Reflection
Profile1
Profile2
CompactProfile3
FullSEAPI
Swing Beans Sound Image I/O Java 2D
CORBA JNI IDL Print Service AWT
• Lightweight, high-performance script engine
• Implemented in Java by Oracle
• Replaces Mozilla Rhino JavaScript interpreter
– Rhino compiled all JavaScript code to bytecode in generated class files.
– Compared to C implementation of Javascript run with JIT compilation,
Rhino had better performance
– Rhino had memory leak since most JVMs don’t clean unused classes
• Nashorn
– compiles scripts in memory and passes bytecode directly to JVM
Nashorn Javascript Engine
20
• Enriched 3D Graphics features
• New SwingNode class
– SwingNode - enables embedding Swing content into JavaFX
– ScheduledService - allows to automatically restart the service
• Enhanced text support
– Hindi and Thai controls
– New Styles - bi-directional text, multi-line etc
• Now Compatible with ARM platforms
Java FX
21
• The JDBC-ODBC Bridge has been removed
– Reason
 The JDBC-ODBC Bridge had been non-supported product
 Was provided with only selected JDKs and not included in JRE
– Alternate recommendation
 Use a JDBC driver provided by the database vendor
 If it was in use to with MS Access DB or Excel spreadsheet etc, could be replaced by
pure java DB like H2, Java DB etc.
• JDBC 4.2
– Minor enhancements to JDBC to improve usability and portability
• JDK 8 includes Java DB 10.10
– a version of the Apache Derby database (since Java 5)
JDBC
22
• URLPermission Represents permission to access
– a resource defined by url
– for a given set of user-settable request methods and request headers
• URLPermission(String url_name, String actions)
– name of the permission is the url string
 http://www.oracle.com/a/b/*
– actions string is a concatenation of the request methods and headers
 "POST,GET,DELETE“
 "POST,GET:Header1,Header2“
• Examples of Path Matching
– public boolean implies(Permission p)
HTTP URL Permission
23
This’s path P’s path Matches /implies
/a/b/* /a/b/c Yes
/a/b/* /a/b/c/d No
/a/b/- /a/b/c/d/e Yes
• KeyStore enhancements
– new Domain KeyStore type java.security.DomainLoadStoreParameter
– new command option - importpassword for the keytool utility
• New variant of AccessController.doPrivileged
– enables code to assert a subset of its privileges, without preventing the
full traversal of the stack to check for other permissions
• Support for
– Stronger algorithms for password-based encryption
– AEAD algorithms
– SHA-224 Message Digests
– rcache Types in Kerberos 5 Replay Caching
Security
24
• Leverage CPU Instructions for AES Cryptography
– Intel Westmere hardware (2010 or newer) has instruction set to
support AES (Advanced Encryption Standard)
– Syntax: -XX:+UseAES -XX:+UseAESIntrinsics
• JMC 5.3
– JMC (Originally developed by JRockit) is an advanced set of tools that
enabling efficient JVM monitoring & profiling
– JMC is bundled with the HotSpot JVM starting from Java SE 7u40
HotSpot VM
25
• New Commands
– Jjs – invoke Nashorn java script engine
– Java – can launch JavaFX
– Jdeps - analyze class files
• Pack200
– Pack200 support for Constant Pool Entries and New Bytecodes
Tools
26
Thank You
END
27

Contenu connexe

Tendances

Tendances (20)

Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8
 
Java SE 8 library design
Java SE 8 library designJava SE 8 library design
Java SE 8 library design
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Java SE 8
Java SE 8Java SE 8
Java SE 8
 
Java 8
Java 8Java 8
Java 8
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaJDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
 

Similaire à Java SE 8 - New Features

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
 
Architectures, Frameworks and Infrastructure
Architectures, Frameworks and InfrastructureArchitectures, Frameworks and Infrastructure
Architectures, Frameworks and Infrastructure
harendra_pathak
 

Similaire à Java SE 8 - New Features (20)

Java SE 8 & EE 7 Launch
Java SE 8 & EE 7 LaunchJava SE 8 & EE 7 Launch
Java SE 8 & EE 7 Launch
 
Java8
Java8Java8
Java8
 
Java 8 in Anger (QCon London)
Java 8 in Anger (QCon London)Java 8 in Anger (QCon London)
Java 8 in Anger (QCon London)
 
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
 
Java 8 in Anger, Devoxx France
Java 8 in Anger, Devoxx FranceJava 8 in Anger, Devoxx France
Java 8 in Anger, Devoxx France
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
Java >= 9
Java >= 9Java >= 9
Java >= 9
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
 
JavaOne 2011 Recap
JavaOne 2011 RecapJavaOne 2011 Recap
JavaOne 2011 Recap
 
Java user group 2015 02-09-java8
Java user group 2015 02-09-java8Java user group 2015 02-09-java8
Java user group 2015 02-09-java8
 
Java user group 2015 02-09-java8
Java user group 2015 02-09-java8Java user group 2015 02-09-java8
Java user group 2015 02-09-java8
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
Architectures, Frameworks and Infrastructure
Architectures, Frameworks and InfrastructureArchitectures, Frameworks and Infrastructure
Architectures, Frameworks and Infrastructure
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Dernier (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Java SE 8 - New Features

  • 1. Java 8 - New Features NaveenHegde Apr 2014
  • 2. Java Version History 2 1996 1998 2000 2002 2004 2006 2011 Java SE 8 Spider 2014 First release developed under the Java Community Process Version 1.5 -> 5 To reflect level of Maturity, Stability J2SE -> Java SE Dropped .0
  • 3. • Java 5 – Generics, Autoboxing – Enhanced For-Loop, VarArgs and more… Recap - Major Feature Additions in Java 3  Java 6 • Script Engine • New I/O • Jconsole, profiler & debug interface (JVMPI, JVMDI)  Java 7 • Strings in Switch, Catch Multiple-Exceptions • Try-with-Resource, Type Interface • JVM Support for Non-Java Languages
  • 4. • Lambda Expressions • Streams Facility • Date-Time Library • permgen replaced by Metaspace • Type Annotations and Repeating Annotations • jdbc-odbc bridge removed • New utilities to improve Performance, Scalability Java SE 8 New Features at glance 4
  • 5. • Treat functionality as method argument (code as data) • Avoid anonymous inner class which seem excessive & unclear • Cleaner way to implement Functional Interfaces • Used to create anonymous methods Lambda Expressions 5 Parameter(s) Body single expression or statement block Lambda Expression Syntax Sample Code for “Sorting persons array by Age” Java compiler determines Lambda Expr Type using new “Target Typing” mechanism
  • 6. • In Swing, JavaFX, Often, event handler interfaces are functional interfaces • Lambda expressions can best replace anonymous classes created for keyboard actions, mouse actions etc Using Lambda Expression in GUI 6
  • 7. • Creation of compact, easy-to-read lambda expressions • Use it with Lambda Expresions for – Encapsulate a single unit of behavior and pass it to other code – Create simple instance of a functional interface Method References 7 Method Reference Type Example to a static method Person::compareByAge to an instance method of a particular object myComparator::compareByName to a method of arbitrary type instance String::compareToIgnoreCase to a constructor HashSet::new
  • 8. • Ability to add default implementation in interfaces • No impact on already existing implementations Default Interface Method 8  Extending Interfaces That Contain Default Methods • Not mention default method -> inherits the default • Redeclare the default method -> makes it abstract. • Redefine the default method -> overrides it Interface with all default methods is like an Adapter
  • 9. • New package for filter/map/reduce transformations on streams • Includes many useful built in aggregate operations java.util.stream.* 9 int ave = Arrays.stream(personArr) .filter(b -> b.getGender() == Gender.MALE) .mapToDouble(Person::getSalary) .average() .getAsDouble(); ‘persons’ is a Collection<Person>  Generating Streams • Collection objects: via the stream() and parallelStream() methods • Array elements: via Arrays.stream(Object[]) • Lines of File : BufferedReader.lines() • Streams of random numbers : Random.ints()
  • 10. • No storage – A stream is not a data structure that stores elements – it conveys elements from a source (Array,Collection,IO Channel etc) through a pipeline of computational operations – stream operation produces a result without modifing its source • Functional in nature – Enable Functional way of Working with Databases – Easy and elegant • Parallelism – Streams facilitate parallel execution by reframing the computation as a pipeline of aggregate operations • Consumable – The elements are visited only once during the life of a stream. – new stream must be generated to revisit the same elements Why use Streams? 10
  • 11. • JavaSE 6 – Date – Calendar – DateFormat – TimeZone Date-Time Packages 11  Java 8 formatter=DateTimeFormatter.ofPattern("yyyy MM dd"); String text = date.toString(formatter); LocalDate date = LocalDate.parse(text, formatter) ChronoUnit.DAYS.between(t1, t2)
  • 12. • Motive – Solve the common scalability problem of “Maintaining a single count, sum, etc. that is updated by many threads” • How? – Internally employ contention-reduction techniques – Provides huge throughput improvements as compared to Atomic variables • Classes – DoubleAccumulator  One or more variables that together maintain a running double value updated using a supplied function. – DoubleAdder  One or more variables that together maintain an initially zero double sum. – LongAccumulator – LongAdder Scalable-Updatable variable support 12
  • 13. • Streams & Lambda expression based new methods – forEach methods  forEach, forEachKey, forEachValue, and forEachEntry – search methods  search, searchKeys, searchValues, and searchEntries – reduction methods  reduce, reduceToDouble, reduceToLong … ConcurrentHashMap Enhancements 13 -> ConcurrentHashMaps (and classes built from them) are more useful as cache
  • 14. • Interfaces – CompletionStage<T>: A stage of a possibly asynchronous computation • Classes – CompletableFuture<T>: A Future that may be explicitly completed  May be used as a CompletionStage,  Supports actions that trigger upon its completion – CountedCompleter<T>: A ForkJoinTask with a completion Action  Action is triggered when there are no remaining pending actions – ConcurrentHashMap.KeySetView<K,V>:  A view of ConcurrentHashMap as a Set of keys  Additions may optionally be enabled by mapping to a common value New Additions to java.util.concurrent 14
  • 15. • Arrays.parallelSort() – Parallel merge-sort algorithm technique using ForkJoinPool • Bulk Data Operations for Collections • Base64 Encoding & Decoding support – New Classes  Base64, Base64.Decoder, Base64.Encoder – Eg Applications of use  Multipurpose Internet Mail Extensions (MIME)  encode passwords for HTTP headers Utils 15
  • 16. • StampedLock – A capability-based lock with three modes for controlling access  1) Reading 2) Writing 3) Optimistic Reading – Lock acquisition methods return a stamp – Stamp represents and controls access with respect to a lock state – Designed for the development of thread-safe components – Not re-entrant • ForkJoinPool (since java7) – ExecutorService for running ForkJoinTasks – A static commonPool() is added to reduce resource usage  Default pool appropriate for most applications – ForkJoinPool differs from other kinds of ExecutorService  Mainly by virtue of employing work-stealing  All threads in the pool attempt to find and execute subtasks created by other tasks or external clients like management and monitoring operations Miscellaneous 16
  • 17. • Repeating Annotations – provide the ability to apply the same annotation type more than once to the same declaration • Type Annotations – provide the ability to apply an annotation anywhere a type is used, not just on a declaration. – Used with a pluggable type system, – this feature enables improved type checking of your code Annotations 17
  • 18. • Motive – Eliminate need for ‘MaxPermSize’ tuning (one of the reasons for OOM error) – Improve GC performance • Removal of PermGen – Most allocations for the class metadata is done out of native memory – Some miscellaneous data has been moved to the Java heap – klasses that were used to described class metadata have been removed – Metaspace is Non-contigeous to heap – A garbage collection may be induced to collect dead classloaders and classes. The first garbage collection will be induced when the class metadata usage reaches MaxMetaspaceSize PermGen replaced by Metaspace 18 Heap NewGen Survivor Space OldGen PermGen Heap NewGen Survivor Space OldGen Metaspace Native Mem PermGen=Region{ Class Metadata, Hierarchy info, Constant Pool, Bytecode …} No more “OutOfMemoryError: PermGen space”
  • 19. • Defines subsets of JRE for devices that have limited storage capacity • Match Application Functional needs closely Compact Profiles 19 Security(E) JMX Instrumentation XML JAXP (E) JDBC RMI XML JAXP Core Networking IO Collections Scripting Regex JNDI Reflection Profile1 Profile2 CompactProfile3 FullSEAPI Swing Beans Sound Image I/O Java 2D CORBA JNI IDL Print Service AWT
  • 20. • Lightweight, high-performance script engine • Implemented in Java by Oracle • Replaces Mozilla Rhino JavaScript interpreter – Rhino compiled all JavaScript code to bytecode in generated class files. – Compared to C implementation of Javascript run with JIT compilation, Rhino had better performance – Rhino had memory leak since most JVMs don’t clean unused classes • Nashorn – compiles scripts in memory and passes bytecode directly to JVM Nashorn Javascript Engine 20
  • 21. • Enriched 3D Graphics features • New SwingNode class – SwingNode - enables embedding Swing content into JavaFX – ScheduledService - allows to automatically restart the service • Enhanced text support – Hindi and Thai controls – New Styles - bi-directional text, multi-line etc • Now Compatible with ARM platforms Java FX 21
  • 22. • The JDBC-ODBC Bridge has been removed – Reason  The JDBC-ODBC Bridge had been non-supported product  Was provided with only selected JDKs and not included in JRE – Alternate recommendation  Use a JDBC driver provided by the database vendor  If it was in use to with MS Access DB or Excel spreadsheet etc, could be replaced by pure java DB like H2, Java DB etc. • JDBC 4.2 – Minor enhancements to JDBC to improve usability and portability • JDK 8 includes Java DB 10.10 – a version of the Apache Derby database (since Java 5) JDBC 22
  • 23. • URLPermission Represents permission to access – a resource defined by url – for a given set of user-settable request methods and request headers • URLPermission(String url_name, String actions) – name of the permission is the url string  http://www.oracle.com/a/b/* – actions string is a concatenation of the request methods and headers  "POST,GET,DELETE“  "POST,GET:Header1,Header2“ • Examples of Path Matching – public boolean implies(Permission p) HTTP URL Permission 23 This’s path P’s path Matches /implies /a/b/* /a/b/c Yes /a/b/* /a/b/c/d No /a/b/- /a/b/c/d/e Yes
  • 24. • KeyStore enhancements – new Domain KeyStore type java.security.DomainLoadStoreParameter – new command option - importpassword for the keytool utility • New variant of AccessController.doPrivileged – enables code to assert a subset of its privileges, without preventing the full traversal of the stack to check for other permissions • Support for – Stronger algorithms for password-based encryption – AEAD algorithms – SHA-224 Message Digests – rcache Types in Kerberos 5 Replay Caching Security 24
  • 25. • Leverage CPU Instructions for AES Cryptography – Intel Westmere hardware (2010 or newer) has instruction set to support AES (Advanced Encryption Standard) – Syntax: -XX:+UseAES -XX:+UseAESIntrinsics • JMC 5.3 – JMC (Originally developed by JRockit) is an advanced set of tools that enabling efficient JVM monitoring & profiling – JMC is bundled with the HotSpot JVM starting from Java SE 7u40 HotSpot VM 25
  • 26. • New Commands – Jjs – invoke Nashorn java script engine – Java – can launch JavaFX – Jdeps - analyze class files • Pack200 – Pack200 support for Constant Pool Entries and New Bytecodes Tools 26