SlideShare a Scribd company logo
Java 8 Features
Lenin Kumar Koppoju
Agenda
• Default Methods
• Static Methods
• Method Reference Operator
• Lambda Expressions (Streams API)
Default Method
• This is a new feature, which allows developer to add new methods to the
interface using default keyword without breaking existing implementation.
• Object class methods are not allowed as default methods.
Extending Interfaces that contain default
methods
• Not mention the default method at all, which lets your extended interface
inherit the default method.
• Re-declare the default method, which makes it abstract.
• Re-define the default method, which overrides it.
Scenario 1: Implementing multiple Interfaces
those contain same name default method
• Use the super keyword to invoke a default method in both classes and
interfaces.
Scenario 2: Implementing Interfaces and
class, those contain same method
• Instance methods are preferred over interface default methods.
Static Method
• This is an extension, which allows developer to add new methods to the
interface using static keyword without breaking existing implementation.
• Object class methods are not allowed as static methods.
Static Method
• Static Methods are belongs to class.
• These methods never override.
• Default or general methods never override with Static Methods in sub
classes.
Method Reference Operator
• A new powerful operator, added with Java 8.
• This operator calls in following ways
• Class :: Static_Method
• Class :: Method
• Instance :: Method
Method Reference Operator
• Keywords super and this can be used with method references.
Lambda Expressions
• A new feature, which allows to write functional programming.
Lambda Expressions
• Functional Interface
• This is an Interface with a single abstract method, called the functional method for that
functional interface, to which the lambda expression's parameter and return types are
matched or adapted.
• It provides target types for lambda expressions and method references.
• Use @FunctionalInterface annotation to identify/confirm functional interface.
Lambda Expressions
• Functional Interface
• These interfaces can provide a target type in multiple contexts, such as assignment
context, method invocation, or cast context.
Lambda Expressions
• Base functional interfaces, which are used frequently in lambda’s.
• Consumer – consumes one argument, returns nothing
• Function – takes one argument, returns one value.
• Predicate – checks one argument, returns Boolean (true or false).
• Supplier – accepts no argument, returns one value.
Lambda Expressions
• Base functional interfaces, for our notes.
• Consumer – process and returns nothing.
• Function – used for mapping, process and returns something.
• Predicate – used for condition, process and returns true or false.
• Supplier – used as a factory, process and returns instance.
Lambda Expressions
• Stream API
• This is newly added API in java.util.stream.
• This introduces real world functional-style programming into java.
• ThisAPI has simplified the collections processing.
• You can create streams from collections, arrays, generators, or iterators.
Lambda Expressions
• Stream API
• Stream class will create Streams with the help of static methods : contact, empty,
generate, iterate, of.
Lambda Expressions
• Streams in parallel
• Parallel Stream can be created using Stream.parallel or Collection.parallerStream
methods.
• This will partition the stream into multiple substreams.
• Aggregate operations iterate over and process these substreams in parallel and then
combine the results.
Lambda Expressions
• Optional
• This a new class added in java.util package to avoid NullPointerException.
• A container object which may or may not contain a non-null value. If a value is present,
isPresent() will return true and get() will return the value.
• Frequently,This class used to be created to return value on safe operations and we can
create using static methods : empty, ofNullable, of.
Lambda Expressions
• Comparator
• This Provides comparison functionality,Which imposes ordering on collection of
objects.
• This is a functional interface with compare abstract method.
• New static methods are added for convenience to create comparators, multiple value
comparing, null values ordering and reverse order.
Lambda Expressions
• Optional
• Getting Optional as return on Stream operations : max, min, reduce, findAny,
findFirst.
Lambda Expressions
• We can convert the streams to other type using map, mapToXXX (Double,
Int, Long) methods.
• These conversion streams will be used get statistics like sum, average, max,
min, count.
Lambda Expressions
• Stream’s Review
Lambda Expressions
• Optional’s Review
Lambda Expressions
• Collectors – to create collects like list, set and map.
Lambda Expressions
• Partitioning
Lambda Expressions
• Grouping
Lambda Expressions
• Statistics
Thank you…
Lenin Kumar Koppoju

More Related Content

What's hot

Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
Manav Prasad
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
NexThoughts Technologies
 
Methods in java
Methods in javaMethods in java
Methods in java
chauhankapil
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Java 10 New Features
Java 10 New FeaturesJava 10 New Features
Java 10 New Features
Ali BAKAN
 
Java8 features
Java8 featuresJava8 features
Java8 features
Elias Hasnat
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
NewCircle Training
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
Haim Michael
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Venkata Naga Ravi
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
LivePerson
 
Oops in java
Oops in javaOops in java
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
atozknowledge .com
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat
 
Spring Boot
Spring BootSpring Boot
Spring Boot
koppenolski
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Operators in java
Operators in javaOperators in java
Operators in java
Madishetty Prathibha
 

What's hot (20)

Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Methods in java
Methods in javaMethods in java
Methods in java
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Java 10 New Features
Java 10 New FeaturesJava 10 New Features
Java 10 New Features
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Oops in java
Oops in javaOops in java
Oops in java
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Java threads
Java threadsJava threads
Java threads
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 

Similar to Java 8 Features

Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
Tobias Coetzee
 
Java 8 Functional Programming - I
Java 8 Functional Programming - IJava 8 Functional Programming - I
Java 8 Functional Programming - I
Ugur Yeter
 
Java+8-New+Features.pdf
Java+8-New+Features.pdfJava+8-New+Features.pdf
Java+8-New+Features.pdf
gurukanth4
 
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
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuSrimanta Sahu
 
Functional Interfaces and Method References.pptx
Functional Interfaces and Method References.pptxFunctional Interfaces and Method References.pptx
Functional Interfaces and Method References.pptx
MuhammadSalman701062
 
Java8
Java8Java8
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
14274730 (1).ppt
14274730 (1).ppt14274730 (1).ppt
14274730 (1).ppt
aptechaligarh
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013
Noopur Gupta
 
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
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
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
Harmeet Singh(Taara)
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
Simon Ritter
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
Srdjan Strbanovic
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
IndicThreads
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Amr Abd El Latief
 
Java
JavaJava
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
Naveen Hegde
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
Rahman USTA
 

Similar to Java 8 Features (20)

Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
Java 8 Functional Programming - I
Java 8 Functional Programming - IJava 8 Functional Programming - I
Java 8 Functional Programming - I
 
Java+8-New+Features.pdf
Java+8-New+Features.pdfJava+8-New+Features.pdf
Java+8-New+Features.pdf
 
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
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
 
Functional Interfaces and Method References.pptx
Functional Interfaces and Method References.pptxFunctional Interfaces and Method References.pptx
Functional Interfaces and Method References.pptx
 
Java8
Java8Java8
Java8
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
 
14274730 (1).ppt
14274730 (1).ppt14274730 (1).ppt
14274730 (1).ppt
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013
 
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
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
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
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Java
JavaJava
Java
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 

Java 8 Features

  • 1. Java 8 Features Lenin Kumar Koppoju
  • 2. Agenda • Default Methods • Static Methods • Method Reference Operator • Lambda Expressions (Streams API)
  • 3. Default Method • This is a new feature, which allows developer to add new methods to the interface using default keyword without breaking existing implementation. • Object class methods are not allowed as default methods.
  • 4. Extending Interfaces that contain default methods • Not mention the default method at all, which lets your extended interface inherit the default method. • Re-declare the default method, which makes it abstract. • Re-define the default method, which overrides it.
  • 5. Scenario 1: Implementing multiple Interfaces those contain same name default method • Use the super keyword to invoke a default method in both classes and interfaces.
  • 6. Scenario 2: Implementing Interfaces and class, those contain same method • Instance methods are preferred over interface default methods.
  • 7. Static Method • This is an extension, which allows developer to add new methods to the interface using static keyword without breaking existing implementation. • Object class methods are not allowed as static methods.
  • 8. Static Method • Static Methods are belongs to class. • These methods never override. • Default or general methods never override with Static Methods in sub classes.
  • 9. Method Reference Operator • A new powerful operator, added with Java 8. • This operator calls in following ways • Class :: Static_Method • Class :: Method • Instance :: Method
  • 10. Method Reference Operator • Keywords super and this can be used with method references.
  • 11. Lambda Expressions • A new feature, which allows to write functional programming.
  • 12. Lambda Expressions • Functional Interface • This is an Interface with a single abstract method, called the functional method for that functional interface, to which the lambda expression's parameter and return types are matched or adapted. • It provides target types for lambda expressions and method references. • Use @FunctionalInterface annotation to identify/confirm functional interface.
  • 13. Lambda Expressions • Functional Interface • These interfaces can provide a target type in multiple contexts, such as assignment context, method invocation, or cast context.
  • 14. Lambda Expressions • Base functional interfaces, which are used frequently in lambda’s. • Consumer – consumes one argument, returns nothing • Function – takes one argument, returns one value. • Predicate – checks one argument, returns Boolean (true or false). • Supplier – accepts no argument, returns one value.
  • 15. Lambda Expressions • Base functional interfaces, for our notes. • Consumer – process and returns nothing. • Function – used for mapping, process and returns something. • Predicate – used for condition, process and returns true or false. • Supplier – used as a factory, process and returns instance.
  • 16. Lambda Expressions • Stream API • This is newly added API in java.util.stream. • This introduces real world functional-style programming into java. • ThisAPI has simplified the collections processing. • You can create streams from collections, arrays, generators, or iterators.
  • 17. Lambda Expressions • Stream API • Stream class will create Streams with the help of static methods : contact, empty, generate, iterate, of.
  • 18. Lambda Expressions • Streams in parallel • Parallel Stream can be created using Stream.parallel or Collection.parallerStream methods. • This will partition the stream into multiple substreams. • Aggregate operations iterate over and process these substreams in parallel and then combine the results.
  • 19. Lambda Expressions • Optional • This a new class added in java.util package to avoid NullPointerException. • A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value. • Frequently,This class used to be created to return value on safe operations and we can create using static methods : empty, ofNullable, of.
  • 20. Lambda Expressions • Comparator • This Provides comparison functionality,Which imposes ordering on collection of objects. • This is a functional interface with compare abstract method. • New static methods are added for convenience to create comparators, multiple value comparing, null values ordering and reverse order.
  • 21. Lambda Expressions • Optional • Getting Optional as return on Stream operations : max, min, reduce, findAny, findFirst.
  • 22. Lambda Expressions • We can convert the streams to other type using map, mapToXXX (Double, Int, Long) methods. • These conversion streams will be used get statistics like sum, average, max, min, count.
  • 25. Lambda Expressions • Collectors – to create collects like list, set and map.