SlideShare una empresa de Scribd logo
1 de 18
Presentation on
New Features in Java 8
Presented By
Dinesh Kumar Pathak
Introduction of Java:
Java is a programming language created by James
Gosling from Sun Microsystems (Sun) in 1991. The
target of Java is to write a program once and then run
this pro
The current version of Java is Java 1.8 which is also
known as Java 8.
The Java language was designed with the following
properties:
1. Platform independent
2. Object-orientated programming language
3. Interpreted and compiled language
4. Automatic memory management
Oops Concept:
Abstraction
Encapsulation
Polymorphism
Inheritance
Dynamic Binding
New Features in Java8:
forEach() method in Iterable interface.
default and static methods in interface.
Functional interfaces and lambda expression.
Java Stream API for Bulk Data Operation on
Collection.
Java Time API.
Collection API improvements.
Concurrency API improvements.
Java IO improvements.
forEach() method in Iterable interface:
Whenever we need to traverse through a Collection,
we need to create an Iterator whose whole purpose is
to iterate over
Java 8 has introduced forEach method
in java.lang.Iterable interface so that while writing
code we focus on logic only.
default and static methods in interface:
If you read forEach method details carefully, you will
notice that it’s defined in Iterable interface but we
know that interfaces can’t have method body.
 From Java 8, interfaces are enhanced to have method
with implementation. We can
use default and static keyword to create interfaces
with method implementation.
Static methods, by definition, are not abstract .
default void forEach(ClassName<? super T> action) {
}
Lambda Expression:
 Implement Functional Programming
Lambda expressions provide anonymous function types to
Java.
– Replace use of anonymous inner classes.
– Provide more functional style of programming in
Java.
doSomething(new DoStuff() {
public boolean isGood(int value) {
return value == 42;
}
});
doSomething(answer -> answer == 42);
Lambda Expressions in GUI
Applications:
 To process events in a graphical user interface (GUI) application, such as
keyboard actions, mouse actions, and scroll actions, you typically create
event handlers, which usually involves implementing a particular interface.
Often, event handler interfaces are functional interfaces; they tend to have
only one method.
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
btn.setOnAction(
event -> System.out.println("Hello World!")
);
Functional Interface:
Single Abstract Method (SAM) type
A functional interface is an interface that has one
abstract method.
– Represents a single function contract.
– Doesn’t mean it only has one method .
@FunctionalInterface annotation
– Helps ensure the functional interface
contract is honoured
– Compiler error if not a SAM
Extension Methods:
Bringing Multiple Inheritance (of Functionality) to Java
 Provide a mechanism to add new methods to existing
interfaces
– Without breaking backwards compatibility
– Gives Java multiple inheritance of behavior, as well as
types (but not state!)
public interface Set extends Collection {
public int size();
... // The rest of the existing Set methods
public T reduce(Reducer r) default Collections.setReducer;
}
Java Stream API:
A new java.util.stream has been added in Java 8 to
perform filter/map/reduce like operations with the
collection.
 This is one of the best feature because we work a lot with
Collections and usually with Big Data, we need to filter out
them based on some conditions.
Collection interface has been extended
with stream() and parallelStream() default methods to get
the Stream for sequential and parallel execution.
parallel processing will be very helpful while working with
huge collections.
Java Time API:
It has always been hard to work with Date, Time and
Time Zones in java. There was no standard approach
or API in java for date and time in Java.
One of the nice addition in Java 8 is the java.time
package that will streamline the process of working
with time in java.
One of the useful class is DateTimeFormatter for
converting date time objects to strings.
Collection API improvements:
Iterator default method
forEachRemaining(ClassName object) to perform the
given action for each remaining element until all elements
have been processed or the action throws an exception.
Collection default method removeIf(Predicate filter) to
remove all of the elements of this collection that satisfy the
given predicate.
Collection spliterator() method returning Spliterator
instance that can be used to traverse elements sequentially
or parallel.
Map replaceAll(), compute(), merge() methods.
Performance Improvement for HashMap
class with Key Collisions, how?
in case of collision till Java 7 it used to store values in
linked list and the search order for link list is O(n), but
in java 8 it forms binary tree (O(log(n))) instead of
linked list. This makes search faster, this would be
useful in case of billions of records getting collide for
same hash key.
Concurrency API improvements:
Files.list(Path dir) that returns a lazily populated
Stream, the elements of which are the entries in the
directory.
Files.lines(Path path) that reads all lines from a file as
a Stream.
Files.find() that returns a Stream that is lazily
populated with Path by searching for files in a file tree
rooted at a given starting file.
BufferedReader.lines() that return a Stream, the
elements of which are lines read from this
BufferedReader.
Nashorn JavaScript Engine:
Lightweight, high-performance JavaScript engine.
– Integrated into JRE .
Use existing javax.script API.
 New command-line tool, jjs, to run JavaScript.
It can run scripts as JavaFX applications
Native javascript arrays are untyped. Nashorn enables
you to use typed java arrays in javascript.
Some Other Features:
Comparator interface has been extended with a lot of
default and static methods for natural ordering,
reverse order etc.
min(), max() and sum() methods in Integer, Long and
Double wrapper classes.
logicalAnd(), logicalOr() and logicalXor() methods in
Boolean class.
JDBC-ODBC Bridge has been removed.
New Features in Java 8
end of presentation
Thank you

Más contenido relacionado

La actualidad más candente

Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Nayden Gochev
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
Nayden Gochev
 

La actualidad más candente (20)

Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
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 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Java8
Java8Java8
Java8
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Java- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solutionJava- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solution
 
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
 
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)
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
Java 8
Java 8Java 8
Java 8
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 Overview
 

Similar a New Features of JAVA SE8

Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 

Similar a New Features of JAVA SE8 (20)

Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 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
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Example Of Import Java
Example Of Import JavaExample Of Import Java
Example Of Import Java
 
Using Java 8 on Android
Using Java 8 on AndroidUsing Java 8 on Android
Using Java 8 on Android
 
Stream Api.pdf
Stream Api.pdfStream Api.pdf
Stream Api.pdf
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
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 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
 
Java 8-revealed
Java 8-revealedJava 8-revealed
Java 8-revealed
 
Java1
Java1Java1
Java1
 
Java
Java Java
Java
 
Java SE 8 & EE 7 Launch
Java SE 8 & EE 7 LaunchJava SE 8 & EE 7 Launch
Java SE 8 & EE 7 Launch
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
 
Java 3 rd sem. 2012 aug.ASSIGNMENT
Java 3 rd sem. 2012 aug.ASSIGNMENTJava 3 rd sem. 2012 aug.ASSIGNMENT
Java 3 rd sem. 2012 aug.ASSIGNMENT
 
14274730 (1).ppt
14274730 (1).ppt14274730 (1).ppt
14274730 (1).ppt
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

New Features of JAVA SE8

  • 1. Presentation on New Features in Java 8 Presented By Dinesh Kumar Pathak
  • 2. Introduction of Java: Java is a programming language created by James Gosling from Sun Microsystems (Sun) in 1991. The target of Java is to write a program once and then run this pro The current version of Java is Java 1.8 which is also known as Java 8. The Java language was designed with the following properties: 1. Platform independent 2. Object-orientated programming language 3. Interpreted and compiled language 4. Automatic memory management
  • 4. New Features in Java8: forEach() method in Iterable interface. default and static methods in interface. Functional interfaces and lambda expression. Java Stream API for Bulk Data Operation on Collection. Java Time API. Collection API improvements. Concurrency API improvements. Java IO improvements.
  • 5. forEach() method in Iterable interface: Whenever we need to traverse through a Collection, we need to create an Iterator whose whole purpose is to iterate over Java 8 has introduced forEach method in java.lang.Iterable interface so that while writing code we focus on logic only.
  • 6. default and static methods in interface: If you read forEach method details carefully, you will notice that it’s defined in Iterable interface but we know that interfaces can’t have method body.  From Java 8, interfaces are enhanced to have method with implementation. We can use default and static keyword to create interfaces with method implementation. Static methods, by definition, are not abstract . default void forEach(ClassName<? super T> action) { }
  • 7. Lambda Expression:  Implement Functional Programming Lambda expressions provide anonymous function types to Java. – Replace use of anonymous inner classes. – Provide more functional style of programming in Java. doSomething(new DoStuff() { public boolean isGood(int value) { return value == 42; } }); doSomething(answer -> answer == 42);
  • 8. Lambda Expressions in GUI Applications:  To process events in a graphical user interface (GUI) application, such as keyboard actions, mouse actions, and scroll actions, you typically create event handlers, which usually involves implementing a particular interface. Often, event handler interfaces are functional interfaces; they tend to have only one method. btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); btn.setOnAction( event -> System.out.println("Hello World!") );
  • 9. Functional Interface: Single Abstract Method (SAM) type A functional interface is an interface that has one abstract method. – Represents a single function contract. – Doesn’t mean it only has one method . @FunctionalInterface annotation – Helps ensure the functional interface contract is honoured – Compiler error if not a SAM
  • 10. Extension Methods: Bringing Multiple Inheritance (of Functionality) to Java  Provide a mechanism to add new methods to existing interfaces – Without breaking backwards compatibility – Gives Java multiple inheritance of behavior, as well as types (but not state!) public interface Set extends Collection { public int size(); ... // The rest of the existing Set methods public T reduce(Reducer r) default Collections.setReducer; }
  • 11. Java Stream API: A new java.util.stream has been added in Java 8 to perform filter/map/reduce like operations with the collection.  This is one of the best feature because we work a lot with Collections and usually with Big Data, we need to filter out them based on some conditions. Collection interface has been extended with stream() and parallelStream() default methods to get the Stream for sequential and parallel execution. parallel processing will be very helpful while working with huge collections.
  • 12. Java Time API: It has always been hard to work with Date, Time and Time Zones in java. There was no standard approach or API in java for date and time in Java. One of the nice addition in Java 8 is the java.time package that will streamline the process of working with time in java. One of the useful class is DateTimeFormatter for converting date time objects to strings.
  • 13. Collection API improvements: Iterator default method forEachRemaining(ClassName object) to perform the given action for each remaining element until all elements have been processed or the action throws an exception. Collection default method removeIf(Predicate filter) to remove all of the elements of this collection that satisfy the given predicate. Collection spliterator() method returning Spliterator instance that can be used to traverse elements sequentially or parallel. Map replaceAll(), compute(), merge() methods.
  • 14. Performance Improvement for HashMap class with Key Collisions, how? in case of collision till Java 7 it used to store values in linked list and the search order for link list is O(n), but in java 8 it forms binary tree (O(log(n))) instead of linked list. This makes search faster, this would be useful in case of billions of records getting collide for same hash key.
  • 15. Concurrency API improvements: Files.list(Path dir) that returns a lazily populated Stream, the elements of which are the entries in the directory. Files.lines(Path path) that reads all lines from a file as a Stream. Files.find() that returns a Stream that is lazily populated with Path by searching for files in a file tree rooted at a given starting file. BufferedReader.lines() that return a Stream, the elements of which are lines read from this BufferedReader.
  • 16. Nashorn JavaScript Engine: Lightweight, high-performance JavaScript engine. – Integrated into JRE . Use existing javax.script API.  New command-line tool, jjs, to run JavaScript. It can run scripts as JavaFX applications Native javascript arrays are untyped. Nashorn enables you to use typed java arrays in javascript.
  • 17. Some Other Features: Comparator interface has been extended with a lot of default and static methods for natural ordering, reverse order etc. min(), max() and sum() methods in Integer, Long and Double wrapper classes. logicalAnd(), logicalOr() and logicalXor() methods in Boolean class. JDBC-ODBC Bridge has been removed.
  • 18. New Features in Java 8 end of presentation Thank you