Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 w...
Extending Interfaces that contain default
methods
• Not mention the default method at all, which lets your extended interf...
Scenario 1: Implementing multiple Interfaces
those contain same name default method
• Use the super keyword to invoke a de...
Scenario 2: Implementing Interfaces and
class, those contain same method
• Instance methods are preferred over interface d...
Static Method
• This is an extension, which allows developer to add new methods to the
interface using static keyword with...
Static Method
• Static Methods are belongs to class.
• These methods never override.
• Default or general methods never ov...
Method Reference Operator
• A new powerful operator, added with Java 8.
• This operator calls in following ways
• Class ::...
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 meth...
Lambda Expressions
• Functional Interface
• These interfaces can provide a target type in multiple contexts, such as assig...
Lambda Expressions
• Base functional interfaces, which are used frequently in lambda’s.
• Consumer – consumes one argument...
Lambda Expressions
• Base functional interfaces, for our notes.
• Consumer – process and returns nothing.
• Function – use...
Lambda Expressions
• Stream API
• This is newly added API in java.util.stream.
• This introduces real world functional-sty...
Lambda Expressions
• Stream API
• Stream class will create Streams with the help of static methods : contact, empty,
gener...
Lambda Expressions
• Streams in parallel
• Parallel Stream can be created using Stream.parallel or Collection.parallerStre...
Lambda Expressions
• Optional
• This a new class added in java.util package to avoid NullPointerException.
• A container o...
Lambda Expressions
• Comparator
• This Provides comparison functionality,Which imposes ordering on collection of
objects.
...
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 con...
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
Upcoming SlideShare
Loading in …5
×

Java 8 Features

560 views

Published on

  • Be the first to comment

  • Be the first to like this

Java 8 Features

  1. 1. Java 8 Features Lenin Kumar Koppoju
  2. 2. Agenda • Default Methods • Static Methods • Method Reference Operator • Lambda Expressions (Streams API)
  3. 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. 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. 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. 6. Scenario 2: Implementing Interfaces and class, those contain same method • Instance methods are preferred over interface default methods.
  7. 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. 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. 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. 10. Method Reference Operator • Keywords super and this can be used with method references.
  11. 11. Lambda Expressions • A new feature, which allows to write functional programming.
  12. 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. 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. 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. 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. 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. 17. Lambda Expressions • Stream API • Stream class will create Streams with the help of static methods : contact, empty, generate, iterate, of.
  18. 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. 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. 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. 21. Lambda Expressions • Optional • Getting Optional as return on Stream operations : max, min, reduce, findAny, findFirst.
  22. 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.
  23. 23. Lambda Expressions • Stream’s Review
  24. 24. Lambda Expressions • Optional’s Review
  25. 25. Lambda Expressions • Collectors – to create collects like list, set and map.
  26. 26. Lambda Expressions • Partitioning
  27. 27. Lambda Expressions • Grouping
  28. 28. Lambda Expressions • Statistics
  29. 29. Thank you… Lenin Kumar Koppoju

×