SlideShare a Scribd company logo
1CONFIDENTIAL
JAVA 8
2CONFIDENTIAL
• Java 8 General Overview
• Lambdas and Functional Interfaces
• Stream API
• Method References
• Interface’s Default and Static Methods
• Optional
• Date/Time API
• Nashorn, JS Engine
Agenda
3CONFIDENTIAL
Java installing problems
Please, pay attention when installing Java 8.
Note! Tomcat 7.0.x does not work with Java 8:
So make sure your JAVA_HOME is not pointing to Java 8 SDK directory or you will get
bunch of errors. Change your JAVA_HOME or configure your project properly.
4CONFIDENTIAL
Overview
JAVA 8 RELEASE (March 18, 2014)
Optional (value wrapper)Lambdas &
Method references
METHODS INSIDE JAVA INTERFACES
Default methods New Utilities
Stream API Date Time API Nashorn, JS Engine
LAMBDAS EXPRESSIONS
6CONFIDENTIAL
Lambdas (closures) syntax
Each lambda expression has two parts separated by an arrow token: the left hand side is our method
arguments, and the right hand side is what we do with those arguments (business logic)
7CONFIDENTIAL
Just compare
And it’s not even about lines of code
8CONFIDENTIAL
Motivation
• Shorter way of writing an implementation of a method for later execution.
• Provides simple horizontal solution that solves the "vertical problem" presented by inner classes.
• Lambda expressions are designed to allow code to be streamlined.
• Lambdas expressions do not produce any extra classes the way nested classes do.
9CONFIDENTIAL
Method reference
Oracle reference guide
“You use lambda expressions to create anonymous methods. Sometimes, however, a lambda expression does
nothing but call an existing method. In those cases, it's often clearer to refer to the existing method by name.”
Kind Example
Reference to a static method ContainingClass::staticMethodName
Reference to an instance method of
a particular object
containingObject::instanceMethodName
Reference to an instance method of
an arbitrary object of a particular
type
ContainingType::methodName
Reference to a constructor ClassName::new
Kinds of methods referencesExample
10CONFIDENTIAL
Functional Interfaces
Conceptually, a functional interface has exactly one abstract method (e.g. Runnable, Callable, Comparator).
11CONFIDENTIAL
Pre-Built function library (java.util.function)
There are a lot of re-usable functional requirements that can be captured by functional interfaces and
lambdas. The designers of Java 8 have captured the common use cases and created a library of functions
… etc.
STREAMS API
13CONFIDENTIAL
Hello, Streams
Streams let you process data in a declarative way. We do not say how to process the data, we
just say what to do with the data.
Let’s say we need to find all transactions of type ‘grocery’ and return a list of transaction
IDs sorted in decreasing order of transaction value.
14CONFIDENTIAL
java.util.stream.Stream: feel the power.
It takes 10 seconds to process 10 filesIt takes 1 second to process 10 files
15CONFIDENTIAL
Streams versus Collections
Q. What is the difference?
Q. So when should I use streams and why?
Q. On demand?
A. In a nutshell, collections are about data and streams are about computations.
A. Use streams when things are computed. A collection is an in-memory data structure, which holds all the
values that the data structure currently has—every element in the collection has to be computed before it can
be added to the collection. In contrast, a stream is a conceptually fixed data structure in which elements are
computed on demand.
A. Yes, look:
limit(2) uses short-
circuiting;
we need to process
only part of the
stream, not all of
it.
16CONFIDENTIAL
So…
Stream as an abstraction for expressing
efficient, SQL-like operations on a
collection of data.
The Streams API will internally
decompose your query to leverage the
multiple cores on your computer.
OPTIONAL
18CONFIDENTIAL
Optional
A. “… a container object which may or may not contain a non-null value...” Java 8 Reference Guide
Q. Of course, the null reference is the source of many problems. But how does Optional solve them?
Q. What is it?
Q. Why do we need them?
A. Because "Null sucks." Doug Le (a professor of computer science)
A. Enough talking; let's see some code!
19CONFIDENTIAL
java.util.Optional usage
Do Something If a Value Is Present
Default Values and Actions
Creating of Optional
Old style
New style
Old style
New style
Rejecting Certain Values Using the filter Method
Old style
New style
METHODSINSIDE JAVA INTERFACES
21CONFIDENTIAL
What are default methods?
Default methods enable you to add new functionality to the interfaces of your libraries and ensure
backward compatibility with code written for older versions of those interfaces.
The forEach isn’t declared by java.util.List nor the java.util.Collection interface yet. The solution would
be to just add the new method to the existing interface and provide the implementation where required in
the JDK. But, once published, it is impossible to add methods to an interface without breaking the existing
implementation
Syntax
22CONFIDENTIAL
Extending interfaces with default methods
When you extend an interface that contains a default method, you can do the following:
 Not mention the default method at all, which lets inherit the default method.
 Redeclare the default method, which makes it abstract.
 Redefine the default method, which overrides it.
23CONFIDENTIAL
Tricks
“What if the class implements two interfaces and both those interfaces define a default method with
the same signature?”
24CONFIDENTIAL
Static methods
Like static methods in classes, you specify that a method definition in an interface is a static method
with the static keyword at the beginning of the method signature. All method declarations in an
interface, including static methods, are implicitly public, so you can omit the public modifier.
Applications. Examples
The Comparator interface has been enhanced with this ability with the default method reversed:
DATE API
26CONFIDENTIAL
Date API. Core ideas.
The new API is driven by three core ideas:
 Domain-driven design. The new API models its domain very precisely with classes that represent
different use cases for Date and Time closely. This differs from previous Java libraries that were quite
poor in that regard.
 Immutable-value classes. One of the serious weaknesses of the existing formatters in Java is that they aren’t
thread-safe. This puts the burden on developers to use them in a thread-safe manner and to think about
concurrency problems in their day-to-day development of date-handling code. The new API avoids this issue
by ensuring that all its core classes are immutable and represent well-defined values.
 Separation of chronologies. The new API allows people to work with different calendaring systems in order to
support the needs of users in some areas of the world, such as Japan or Thailand, that don’t necessarily follow
ISO-8601. It does so without imposing additional burden on the majority of developers, who need to work only
with the standard chronology
27CONFIDENTIAL
Date API. Creating.
The first classes you will probably encounter when using the new API are LocalDate and LocalTime.
Standard Java getter conventions are used in order to obtain values from Java SE 8 classes
28CONFIDENTIAL
Date API. Creating (2).
There are also methods for calculations based on the different fields.
The new API also has the concept of an adjuster— a block of code that can be used to wrap
up common processing logic
29CONFIDENTIAL
Date API. Go ahead.
The new API supports different precision time points by offering types to represent a date, a
time, and date with time, but obviously there are notions of precision that are more fine-
grained than this.
Time Zones
A time zone is a set of rules, corresponding to a region in which the standard time is the same
NASHORN. JS ENGINE
31CONFIDENTIAL
Nashorn. JS Engine.
Nashorn's goal is to implement a lightweight high-performance JavaScript runtime in Java with a
native JVM.
MyScript.js
32CONFIDENTIAL
?questions and answers
33CONFIDENTIAL
http://docs.oracle.com/Follow to get more

More Related Content

What's hot

java 8 new features
java 8 new features java 8 new features
java 8 new features
Rohit Verma
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
LivePerson
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Venkata Naga Ravi
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
Logan Chien
 
Java 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
Indrajit Das
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
Manvendra Singh
 
Java8 features
Java8 featuresJava8 features
Java8 features
Elias Hasnat
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
Prof. Erwin Globio
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
Surendar Meesala
 
Java Collections
Java CollectionsJava Collections
Java Collectionsparag
 
Introduction to Java 11
Introduction to Java 11 Introduction to Java 11
Introduction to Java 11
Knoldus Inc.
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 

What's hot (20)

java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
07 java collection
07 java collection07 java collection
07 java collection
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Java 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Introduction to Java 11
Introduction to Java 11 Introduction to Java 11
Introduction to Java 11
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 

Viewers also liked

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
Martin Toshev
 
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
Simon Ritter
 
Cracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 ExamsCracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 Exams
Ganesh Samarthyam
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8
Ganesh Samarthyam
 
Supercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-reactSupercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-react
John McClean
 
Sailing with Java 8 Streams
Sailing with Java 8 StreamsSailing with Java 8 Streams
Sailing with Java 8 Streams
Ganesh Samarthyam
 

Viewers also liked (7)

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
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
 
Cracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 ExamsCracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 Exams
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8
 
Supercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-reactSupercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-react
 
Sailing with Java 8 Streams
Sailing with Java 8 StreamsSailing with Java 8 Streams
Sailing with Java 8 Streams
 

Similar to Java 8 - Features Overview

Insight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FPInsight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
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
Emiel Paasschens
 
Java 8
Java 8Java 8
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
Mohammad Faizan
 
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Coen De Roover
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
Geertjan Wielenga
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
deonpmeyer
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
Ali Muzaffar
 
Java 8-revealed
Java 8-revealedJava 8-revealed
Java 8-revealed
Hamed Hatami
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
Tobias Coetzee
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
New York City College of Technology Computer Systems Technology Colloquium
 
Java 8
Java 8Java 8
Java 8
Raghda Salah
 
Java 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CCJava 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CC
JWORKS powered by Ordina
 
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
Raffi Khatchadourian
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
Mindsmapped Consulting
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
javatrainingonline
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014Nayden Gochev
 
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
panagenda
 

Similar to Java 8 - Features Overview (20)

Insight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FPInsight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FP
 
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
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
 
Java 8
Java 8Java 8
Java 8
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
Java 8-revealed
Java 8-revealedJava 8-revealed
Java 8-revealed
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
 
Java 8
Java 8Java 8
Java 8
 
Java 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CCJava 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CC
 
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
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Java 8 - Features Overview

  • 2. 2CONFIDENTIAL • Java 8 General Overview • Lambdas and Functional Interfaces • Stream API • Method References • Interface’s Default and Static Methods • Optional • Date/Time API • Nashorn, JS Engine Agenda
  • 3. 3CONFIDENTIAL Java installing problems Please, pay attention when installing Java 8. Note! Tomcat 7.0.x does not work with Java 8: So make sure your JAVA_HOME is not pointing to Java 8 SDK directory or you will get bunch of errors. Change your JAVA_HOME or configure your project properly.
  • 4. 4CONFIDENTIAL Overview JAVA 8 RELEASE (March 18, 2014) Optional (value wrapper)Lambdas & Method references METHODS INSIDE JAVA INTERFACES Default methods New Utilities Stream API Date Time API Nashorn, JS Engine
  • 6. 6CONFIDENTIAL Lambdas (closures) syntax Each lambda expression has two parts separated by an arrow token: the left hand side is our method arguments, and the right hand side is what we do with those arguments (business logic)
  • 7. 7CONFIDENTIAL Just compare And it’s not even about lines of code
  • 8. 8CONFIDENTIAL Motivation • Shorter way of writing an implementation of a method for later execution. • Provides simple horizontal solution that solves the "vertical problem" presented by inner classes. • Lambda expressions are designed to allow code to be streamlined. • Lambdas expressions do not produce any extra classes the way nested classes do.
  • 9. 9CONFIDENTIAL Method reference Oracle reference guide “You use lambda expressions to create anonymous methods. Sometimes, however, a lambda expression does nothing but call an existing method. In those cases, it's often clearer to refer to the existing method by name.” Kind Example Reference to a static method ContainingClass::staticMethodName Reference to an instance method of a particular object containingObject::instanceMethodName Reference to an instance method of an arbitrary object of a particular type ContainingType::methodName Reference to a constructor ClassName::new Kinds of methods referencesExample
  • 10. 10CONFIDENTIAL Functional Interfaces Conceptually, a functional interface has exactly one abstract method (e.g. Runnable, Callable, Comparator).
  • 11. 11CONFIDENTIAL Pre-Built function library (java.util.function) There are a lot of re-usable functional requirements that can be captured by functional interfaces and lambdas. The designers of Java 8 have captured the common use cases and created a library of functions … etc.
  • 13. 13CONFIDENTIAL Hello, Streams Streams let you process data in a declarative way. We do not say how to process the data, we just say what to do with the data. Let’s say we need to find all transactions of type ‘grocery’ and return a list of transaction IDs sorted in decreasing order of transaction value.
  • 14. 14CONFIDENTIAL java.util.stream.Stream: feel the power. It takes 10 seconds to process 10 filesIt takes 1 second to process 10 files
  • 15. 15CONFIDENTIAL Streams versus Collections Q. What is the difference? Q. So when should I use streams and why? Q. On demand? A. In a nutshell, collections are about data and streams are about computations. A. Use streams when things are computed. A collection is an in-memory data structure, which holds all the values that the data structure currently has—every element in the collection has to be computed before it can be added to the collection. In contrast, a stream is a conceptually fixed data structure in which elements are computed on demand. A. Yes, look: limit(2) uses short- circuiting; we need to process only part of the stream, not all of it.
  • 16. 16CONFIDENTIAL So… Stream as an abstraction for expressing efficient, SQL-like operations on a collection of data. The Streams API will internally decompose your query to leverage the multiple cores on your computer.
  • 18. 18CONFIDENTIAL Optional A. “… a container object which may or may not contain a non-null value...” Java 8 Reference Guide Q. Of course, the null reference is the source of many problems. But how does Optional solve them? Q. What is it? Q. Why do we need them? A. Because "Null sucks." Doug Le (a professor of computer science) A. Enough talking; let's see some code!
  • 19. 19CONFIDENTIAL java.util.Optional usage Do Something If a Value Is Present Default Values and Actions Creating of Optional Old style New style Old style New style Rejecting Certain Values Using the filter Method Old style New style
  • 21. 21CONFIDENTIAL What are default methods? Default methods enable you to add new functionality to the interfaces of your libraries and ensure backward compatibility with code written for older versions of those interfaces. The forEach isn’t declared by java.util.List nor the java.util.Collection interface yet. The solution would be to just add the new method to the existing interface and provide the implementation where required in the JDK. But, once published, it is impossible to add methods to an interface without breaking the existing implementation Syntax
  • 22. 22CONFIDENTIAL Extending interfaces with default methods When you extend an interface that contains a default method, you can do the following:  Not mention the default method at all, which lets inherit the default method.  Redeclare the default method, which makes it abstract.  Redefine the default method, which overrides it.
  • 23. 23CONFIDENTIAL Tricks “What if the class implements two interfaces and both those interfaces define a default method with the same signature?”
  • 24. 24CONFIDENTIAL Static methods Like static methods in classes, you specify that a method definition in an interface is a static method with the static keyword at the beginning of the method signature. All method declarations in an interface, including static methods, are implicitly public, so you can omit the public modifier. Applications. Examples The Comparator interface has been enhanced with this ability with the default method reversed:
  • 26. 26CONFIDENTIAL Date API. Core ideas. The new API is driven by three core ideas:  Domain-driven design. The new API models its domain very precisely with classes that represent different use cases for Date and Time closely. This differs from previous Java libraries that were quite poor in that regard.  Immutable-value classes. One of the serious weaknesses of the existing formatters in Java is that they aren’t thread-safe. This puts the burden on developers to use them in a thread-safe manner and to think about concurrency problems in their day-to-day development of date-handling code. The new API avoids this issue by ensuring that all its core classes are immutable and represent well-defined values.  Separation of chronologies. The new API allows people to work with different calendaring systems in order to support the needs of users in some areas of the world, such as Japan or Thailand, that don’t necessarily follow ISO-8601. It does so without imposing additional burden on the majority of developers, who need to work only with the standard chronology
  • 27. 27CONFIDENTIAL Date API. Creating. The first classes you will probably encounter when using the new API are LocalDate and LocalTime. Standard Java getter conventions are used in order to obtain values from Java SE 8 classes
  • 28. 28CONFIDENTIAL Date API. Creating (2). There are also methods for calculations based on the different fields. The new API also has the concept of an adjuster— a block of code that can be used to wrap up common processing logic
  • 29. 29CONFIDENTIAL Date API. Go ahead. The new API supports different precision time points by offering types to represent a date, a time, and date with time, but obviously there are notions of precision that are more fine- grained than this. Time Zones A time zone is a set of rules, corresponding to a region in which the standard time is the same
  • 31. 31CONFIDENTIAL Nashorn. JS Engine. Nashorn's goal is to implement a lightweight high-performance JavaScript runtime in Java with a native JVM. MyScript.js

Editor's Notes

  1. Java 8 by Sergii Stets
  2. Agenda
  3. Before starting I want pay your attention to some problems you might have when installing new Java 8 SDK. If you use any Tomcat of version 7 on your local machine you will probably fail to run it on top of Java 8. Because Apache Tomcat 7 is not compatible with Java 8. So there are several options: you have to update your Tomcat. Or if you do not want any updates, make sure your JAVA_HOME is not pointing to Java 8 SDK directory.
  4. So the first Java 8 release was at the 18-th of March in 2014. Later on Oracle released different security updates, different patches and so on. The main features of Java 8 are: Lambda expression - Adds functional processing capability to JAVA. Optional - Emphasis on best practices, to handle null values properly. Default method - Interface to have default method implementation. New Tools - New compiler tools and utilities are added like jdeps to figure out the dependencies. Stream API - New stream API to facilitate pipeline processing. Date Time API - Improved date time api. Nashorn , JavaScript Engine - A JAVA based engine to execute JavaScript code.
  5. This is Duke 
  6. Each lambda expression has two parts separated by an arrow token: the left hand side is our method arguments, and the right hand side is what we do with those arguments (business logic) Let’s take a look at the example below. 1 2 as you may have noticed we omitted types of the arguments and that OK. You will understand it later. 3 If your business logic is much more complex than just a line of code you may use curly braces. 4 no args
  7. And it’s not even about lines of code. Lambdas expressions do not produce any extra classes the way inner classes do – so you don’t overheat JVM with a lot of class files it should load into memory. Lambdas has some low-level implementation. It is not just a syntax sugar over nested classes.
  8. Useful info: When to Use Nested Classes, Local Classes, Anonymous Classes, and Lambda Expressions As mentioned in the section Nested Classes, nested classes enable you to logically group classes that are only used in one place, increase the use of encapsulation, and create more readable and maintainable code. Local classes, anonymous classes, and lambda expressions also impart these advantages; however, they are intended to be used for more specific situations: Local class: Use it if you need to create more than one instance of a class, access its constructor, or introduce a new, named type (because, for example, you need to invoke additional methods later). Anonymous class: Use it if you need to declare fields or additional methods. Lambda expression: Use it if you are encapsulating a single unit of behavior that you want to pass to other code. For example, you would use a lambda expression if you want a certain action performed on each element of a collection, when a process is completed, or when a process encounters an error. Use it if you need a simple instance of a functional interface and none of the preceding criteria apply (for example, you do not need a constructor, a named type, fields, or additional methods). Nested class: Use it if your requirements are similar to those of a local class, you want to make the type more widely available, and you don't require access to local variables or method parameters. Use a non-static nested class (or inner class) if you require access to an enclosing instance's non-public fields and methods. Use a static nested class if you don't require this access.
  9. You use lambda expressions to create anonymous methods. Sometimes a lambda expression does nothing but call an existing method. In those cases, it's often clearer to refer to the existing method by name. So Oracle has just created a so called syntax sugar. There different kinds of method references…
  10. Lambdas expressed single method classes. They can either be assigned to a variable or passed around to other methods just like we pass data as arguments. And here where functional interfaces come into. Conceptually, a functional interface has exactly one abstract method. Well know classes: (e.g. Runnable, Callable, Comparator). In Java 8 all the mentioned classes are marked with @FunctionalInterface annotation. It just a marker you may not use it. An informative annotation used to indicate that an interface is intended to be a functional interface as defined by the Java Language Specification. Conceptually, a functional interface has exactly one abstract method 1 We tell the compiler ‘I want to implement check method from ITrade so to someone else can pass me as arguments to another method’ 2 The second one is the same. 3 We do not change the signature of our method, we just pass different trend lambdas http://radar.oreilly.com/2014/08/java-8-functional-interfaces.html
  11. http://radar.oreilly.com/2014/08/java-8-functional-interfaces.html
  12. http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html Streams let you process data in a declarative way. We do not say how to process the data, we just say what to do with the data. Example … By the way Stream operations that can be connected are called intermediate operations. 
  13. Power of parallel streams
  14. … (in the end) This is because limit(2) uses short-circuiting; we need to process only part of the stream, not all of it, to return a result. List<String> phrases = Arrays.asList( "sporadic perjury", "confounded skimming", "incumbent jailer", "confounded jailer"); List<String> uniqueWords = phrases .stream() .flatMap(phrase -> Stream.of(phrase.split(" +"))) .distinct() .sorted() .collect(Collectors.toList()); System.out.println("Unique words: " + uniqueWords);... and the output: Unique words: [confounded, incumbent, jailer, perjury, skimming, sporadic]
  15. http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html
  16. http://geekabyte.blogspot.co.il/2015/01/using-optional-effectively-in-java-8.html http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html You use orElse() in situation where you want to have an alternative value in case T is null. orElseGet() method is similar to orElse(), but instead of providing an alternative, should in case null is encountered, you provide code which can be used to generate the alternative value . orElseThrow() comes in handy when you want to decide which exception to throw in case a null value is encountered. 
  17. Default methods
  18. http://zeroturnaround.com/rebellabs/java-8-explained-default-methods/ http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html
  19. Just read! http://zeroturnaround.com/rebellabs/java-8-explained-default-methods/ http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html
  20. The primary goal of default methods is to enable an evolution of standard JDK interfaces and provide a smooth experience when we finally start using lambdas in Java 8. Who knows, maybe in the future we will see some more applications of default methods for API design.
  21. This example demonstrates how the Comparator interface has been enhanced with default methods, static methods, lambda expressions, and method references to create more expressive library methods whose functionality programmers can quickly deduce by looking at how they are invoked. Use these constructs to enhance the interfaces in your libraries.
  22. http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
  23. http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
  24. http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
  25. http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
  26. Nashorn
  27. http://openjdk.java.net/projects/nashorn/ http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html Nashorn's goal is to implement a lightweight high-performance JavaScript runtime in Java with a native JVM. 
  28. If you have any questions, please do not hesitate to ask me. I will send you homework later.