SlideShare a Scribd company logo
Java 8 New Features
and enhancements
Aniket Thakur
Interface Basics
• What we know so far
• What is an interface?
• Variables in an interface?
• Methods in an interface?
• Interface Vrs Abstract class?
interface A
{
void printEmployeeNames(String division);
}
interface B
{
void printEmployeeNames(String division);
}
class AB implements A,B
{
@Override
public void printEmployeeNames(String division)
{
//print employee names based on division
}
}
public class HelloWorld
{
public static void main(String args[])
{
new AB().printEmployeeNames(”Security");
}
}
Will this work?
Java 8 changes in interface
• Static Methods are allowed
• Eg.
interface A
{
static void printEmployeeNames(String division)
{
//print employee names based on division
}
}
Default Methods
• Provide default implementation of methods defined in an
interface.
• Don’t have to make changes in all concrete subclasses
implementing the interface
Eg –
interface A {
default void printEmployeeNames(String division) {
//print employee names based on division
}
}
interface A {
default void printEmployeeNames(String division) {
//print employee names based on division
}
}
interface B {
default void printEmployeeNames(String division) {
//print employee names based on division
}
}
class AB implements A,B {
}
//make an instance of AB and call printEmployeeNames
Will this work?
interface A {
default void printEmployeeNames(String division) {
//print employee names based on division
}
}
interface B {
default void printEmployeeNames(String division) {
//print employee names based on division
}
}
class AB implements A,B {
@Override
public void printEmployeeNames(String division) {
A.super.printEmployeeNames(division);//whats this?
//print employee names based on division
}
}
//make an instance of AB and call printEmployeeNames
Will this work?
Final local variable(effectively
final)
public void foo() {
final String x = "hello";
String y = "there";
Runnable runnable = new Runnable() {
@Override public void run() {
System.out.println(x);
System.out.println(y);
}
};
runnable.run();
}
Changes in HashMap
• Using Balanced trees instead of Linked List
• Improves worst case performance from O(n) to O(log n).
• Implementation in -
• java.util.HashMap,
• java.util.LinkedHashMap and
• java.util.concurrent.ConcurrentHashMap.
Functional Interfaces
• Interface with just one abstract method.
Eg. –
interface MyInterface {
int getAge();
}
• How about?
interface A {
boolean equals(Object obj);
int getAge();
}
How about?
interface A {
default void printEmployeeNames(String division) {}
static void newMethod(){}
int getAge();
}
• OR
interface A {
public boolean equals(Object obj);
default void printEmployeeNames(String division) {}
static void newMethod(){}
int getAge();
int getNewAge();
}
Seen before?
@FunctionalInterface
public interface Runnable {
public abstract void run();
}
OR
@FunctionalInterface
public interface Comparator<T> {
int compare(T o1, T o2);
}
About Functional interfaces
• Any public method defined by Object, any default methods or
any static methods do not affect the functional status of an
functional interface. As long as it has just one abstract
method.
• Questions?
Common functional interfaces
• Part of java.util.function
• https://docs.oracle.com/javase/8/docs/api/java/util/function/
package-summary.html
• The convention used here us generic type T for type
parameter, for second type parameter the next letter U and
for a distinct return type R is used as the generic type.
Predicate
• Takes a single paramter of any type and returns a boolean
@FunctionalInterface // what’s this?
public interface Predicate<T> {
/**
* Evaluates this predicate on the given argument.
*
* @param t the input argument
* @return {@code true} if the input argument matches the
predicate,
* otherwise {@code false}
*/
boolean test(T t);
//other methods
}
Consumer
• Takes a single paramter of any type and has a void return type
@FunctionalInterface
public interface Consumer<T> {
/**
* Performs this operation on the given argument.
*
* @param t the input argument
*/
void accept(T t);
}
Supplier
• Does not take any parameter and returns any type
@FunctionalInterface
public interface Supplier<T> {
/**
* Gets a result.
*
* @return a result
*/
T get();
}
UnaryOperator
• Takes a single parameter of any type and returns of same type
@FunctionalInterface
public interface Function<T, R> {
/**
* Applies this function to the given argument.
*
* @param t the function argument
* @return the function result
*/
R apply(T t);
}
Java 8 new features
Lambda Expressions
• Lambda expression implements the abstract method in a
functional interface.
• Kind of anonymous class. Also called closures.
Types
• Expression Lamdas
• Block Lambdas
interface MyInterface {
boolean isAllowedAge(int currentAge, int minAge);
}
MyInterface myInterface = (n,m) -> n>=m;//expression
System.out.println(myInterface.isAllowedAge(4,5));
MyInterface myInterface = (n,m) -> { //block
int minAge = m;
if (n >= minAge )
return true;
else
return false;
}
System.out.println(myInterface.isAllowedAge(4,5));
Similarities n Difference
• Block lambdas must have return statements unlike expression ones
where RHS is the return value.
• We can omit specifying argument types. It is automatically inferred
from Functional interface.
• You can have local variables, loops , case statement in you block.
• Same access rules as inner classes.
• Same goes for exception handling. You lambda expression can throw
checked exception but so must you abstract method (compatibility).
• Eg.
Runnable myRunner= () ->{
System.out.println("I am running");
};
Power Of Lambda expression
• What makes Lambda expressions so special?
• Deferred execution
• You can now send executable code as method argument.
• More later 
Say hello to Generics
• lambda expression themselves cannot have generics but the functional interface that
corresponds to a lambda expression can have generics.
Eg.
public class HelloWorld {
public static void main(String args[]) {
MyInterface<String> myStringInterface = (input) -> "Hello " + input;
MyInterface<Integer> myIntInterface = (input) -> 10 + input;
System.out.println("String based lambda exp : " + myStringInterface.myFunc(”I am
Groot"));
System.out.println("Integer based labmda exp : " + myIntInterface.myFunc(14));
}
}
interface MyInterface<T> {
T myFunc(T t);
}
Questions?
Revisiting common functional
interfaces
• Predicate :
Predicate<String> emptyPredicate = x -> x.isEmpty();
System.out.println(emptyPredicate.test(""));
System.out.println(emptyPredicate.test("abc"));
• Consumer :
Consumer<String> printFunc = x -> System.out.println(x);
printFunc.accept("Hello World!");
• Supplier :
Supplier<String> strSupplier = () -> "SOME_CONSTANT";
System.out.println(strSupplier.get());
• UnaryOperator
UnaryOperator<String> prefixOp = (name) -> "Mr. " + name;
System.out.println(prefixOp.apply("Aniket"));
Method references
• Because Lambda expressions were not enough 
• 4 types –
• Reference to a static method
• Reference to a constructor
• Reference to an instance method of an arbitrary object of a
particular type
• Reference to an instance method of a particular object
1. Reference to a static
method
List<String> platforms=
Arrays.asList(“Android”,”iOS”,”Windows”,”IDontCare”);
Consumer<List<String>> methodRef1 = Collections::sort;
methodRef1.accept(platforms);
System.out.println(platforms);
• Equivalent Lambda :
Consumer<List<String>> lambdaRef1 = l -> Collections.sort(l);
2. Reference to a constructor
Supplier<ArrayList<String>> methodRef2 = ArrayList::new;
List<String> newEmployeeNameList = methodRef2.get();
newEmployeeNameList.add(”Intern1");
newEmployeeNameList.add(”Intern2");
System.out.println(newEmployeeNameList);
• Equivalent Lambda :
Supplier<ArrayList> lambdaRef2 = () -> new ArrayList();
• Advice : Try not to look at LHS for functional interface types
and try to guess what kind of interface it is. Coz later we will
directly use it in method arguments. More good stuff to follow

3. Referenceto an instance methodof an
arbitraryobjectof a particulartype
Predicate<String> methodRef3 = String::isEmpty;
String emtptyString = "";
System.out.println(methodRef3.test(emtptyString));
• Equivalent Lambda :
Predicate<String> lambdaRef3 = s -> s.isEmpty();
4. Referenceto an instance methodof a
particularobject
String myName = "Aniket";
Predicate<String> methodRef4 = myName::contains;
System.out.println(methodRef4.test("ike"));
• Equivalent Lambda :
Predicate<String> lambda2 = s -> s.contains(“ike”);
Questions?
Stream API
• Basically sequence of data on which you can operate.
• Three essential parts –
• Source
• Think of this as data set used to generate a stream. Depending on
this a stream can be
• Finite Or
• Infinite
• Intermediate operations
• These operations you can perform on the data set to filter our or
process your data. You can use as many as you desire. One
intermediate operation will give you stream back so that you can
perform additional intermediate operations on it.
• Terminal operations
• These operations produce final results. Only one terminal operation
is allowed per stream.
Generating a Stream
Stream<String> emptyStream =
Stream.empty(); Stream<Integer> singleElementStream =
Stream.of(1); Stream<Integer> streamFromArray =
Stream.of(1,2,3,4);
List<String> listForStream =
Arrays.asList("ABC","PQR","XYZ"); Stream<String>
streamFromList = listForStream.stream(); //most helpful
Stream<Double> randomInfiniteStream =
Stream.generate(Math::random); // what’s this?
Stream<Integer> sequencedInfiniteStream = Stream.iterate(1, n
-> n+1);//what’s this?
Operations
• Common intermediate operations :
• filter()
• distinct()
• limit() and skip()
• map()
• sorted()
• peek()
• Common terminal operations :
• allMatch()/anyMatch()/noneMatch()
• collect()
• count()
• findAny()/findFirst()
• forEach()
• min()/max()
• reduce()
None of these affect the underlying data set (Unless you do something to
change it)
Terminal operations
Examples!
• How about printing a Stream?
List<String> listForStream =
Arrays.asList("ABC","PQR","XYZ"); Stream<String>
streamFromList = listForStream.stream();
//printing using forEach terminal
operation streamFromList.forEach(System.out::println);
//recreate stream as stream once operated on is
invalid streamFromList = listForStream.stream();
//printing using peek intermediate
operation streamFromList.peek(System.out::println).count()
; streamFromList = listForStream.stream();
//printing using collect terminal
operation System.out.println(streamFromList.collect(Collect
ors.toList()));
Some more…
List<String> listForStream = Arrays.asList(”India", ”USA",
”Russia", ”Iran", ”Italy", ”Iraq", ”Bhutan");
Stream<String> streamFromList = listForStream.stream();
streamFromList
.filter(x -> x.startsWith(“I"))
.sorted()
.limit(3)
.forEach(System.out::println);
N more…
Stream.iterate(1, n -> n+1)
.filter(x -> x%5==0)
.limit(5)
.forEach(System.out::println);
Stream.iterate(1, n -> n+1)
.filter(x -> x%5==0)
.peek(System.out::println)
.limit(5)
.forEach(System.out::println);
java.util.ConcurrentModificationException
• Same as iterator do not modify the underlying collection while
processing it’s stream. Else you will get -
java.util.ConcurrentModificationException
• Eg.
List<String> listForStream = new
ArrayList<>(Arrays.asList("ABC","PQR","XYZ"));
Stream<String> streamFromList =
listForStream.stream(); streamFromList.forEach(elm ->
listForStream.remove(elm));//boom
System.out.println(listForStream);
Last but not the least
• Other topics you can cover on your own
1. Optional class and it’s usage (Specially in Spring MVC)
2. New NIO.2 APIs – Path, Files, walking dir etc.
3. Stream for primitives – IntStream, LongStream, DoubleStream
etc
4. Parallel stream – multi threading involved
5. ExecutorService – Callable , Runnable are functional interfaces
6. New Date/Time API
Java SE 8 OCP Programmer
• If you already have Java 7 certification :
• http://education.oracle.com/pls/web_prod-plq-
dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:
1Z0-810
• If you have Java 6 or prior certification :
• https://education.oracle.com/pls/web_prod-plq-
dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:
1Z0-813
• First timers :
• You need to give associate level exam first :
• https://education.oracle.com/pls/web_prod-plq-
dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-
808
• Then you can give professional once :
• https://education.oracle.com/pls/web_prod-plq-
dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-
809
Java 8 new features
Ad

More Related Content

What's hot (20)

Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
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
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
Knoldus Inc.
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
LivePerson
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Venkata Naga Ravi
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
Mark Harrison
 
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)
Harmeet Singh(Taara)
 
Java 8
Java 8Java 8
Java 8
Sudipta K Paik
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
Martin Toshev
 
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)
 
A Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIA Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its API
Jörn Guy Süß JGS
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
Logan Chien
 
Lambdas and Laughs
Lambdas and LaughsLambdas and Laughs
Lambdas and Laughs
Jim Bethancourt
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
Andrzej Grzesik
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
Dinesh Pathak
 
Java 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
Indrajit Das
 
Java SE 8 library design
Java SE 8 library designJava SE 8 library design
Java SE 8 library design
Stephen Colebourne
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
Todor Kolev
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
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
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
Knoldus Inc.
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
LivePerson
 
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)
Harmeet Singh(Taara)
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
Martin Toshev
 
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)
 
A Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIA Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its API
Jörn Guy Süß JGS
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
Logan Chien
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
Dinesh Pathak
 
Java 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
Indrajit Das
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
Todor Kolev
 

Viewers also liked (20)

ARM Processor
ARM ProcessorARM Processor
ARM Processor
Aniket Thakur
 
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
 
Java 8 ​and ​Best Practices
 Java 8 ​and ​Best Practices Java 8 ​and ​Best Practices
Java 8 ​and ​Best Practices
WSO2
 
Xtend - better java with -less- noise
Xtend - better java with -less- noiseXtend - better java with -less- noise
Xtend - better java with -less- noise
Neeraj Bhusare
 
Symbian OS With ARM Processor
Symbian OS With ARM ProcessorSymbian OS With ARM Processor
Symbian OS With ARM Processor
alok3089
 
Jvm fundamentals
Jvm fundamentalsJvm fundamentals
Jvm fundamentals
Miguel Pastor
 
Los Angeles R users group - July 12 2011 - Part 2
Los Angeles R users group - July 12 2011 - Part 2Los Angeles R users group - July 12 2011 - Part 2
Los Angeles R users group - July 12 2011 - Part 2
rusersla
 
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
Eclipse Day India
 
Pub med
Pub medPub med
Pub med
rociosanchoduran
 
CompletableFuture
CompletableFutureCompletableFuture
CompletableFuture
koji lin
 
Growth Hackers of Vienna MeetUp #1 Jan
Growth Hackers of Vienna MeetUp #1 JanGrowth Hackers of Vienna MeetUp #1 Jan
Growth Hackers of Vienna MeetUp #1 Jan
Growth Hackers of Vienna
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors Framework
Arun Mehra
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
Trung Nguyen
 
Networking in java
Networking in javaNetworking in java
Networking in java
shravan kumar upadhayay
 
Arm rit design_comp 2014
Arm rit design_comp 2014Arm rit design_comp 2014
Arm rit design_comp 2014
Antonio Mondragon
 
2013 ARM Student Design Competition @RIT
2013 ARM Student Design Competition @RIT 2013 ARM Student Design Competition @RIT
2013 ARM Student Design Competition @RIT
Antonio Mondragon
 
4th ARM Developer Day Presentation
4th ARM Developer Day Presentation4th ARM Developer Day Presentation
4th ARM Developer Day Presentation
Antonio Mondragon
 
4th ARM Developer Day Presenters info
4th ARM Developer Day Presenters info4th ARM Developer Day Presenters info
4th ARM Developer Day Presenters info
Antonio Mondragon
 
Los jaliles pesados
Los jaliles pesadosLos jaliles pesados
Los jaliles pesados
Antonio Mondragon
 
Exp w21
Exp w21Exp w21
Exp w21
SelectedPresentations
 
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
 
Java 8 ​and ​Best Practices
 Java 8 ​and ​Best Practices Java 8 ​and ​Best Practices
Java 8 ​and ​Best Practices
WSO2
 
Xtend - better java with -less- noise
Xtend - better java with -less- noiseXtend - better java with -less- noise
Xtend - better java with -less- noise
Neeraj Bhusare
 
Symbian OS With ARM Processor
Symbian OS With ARM ProcessorSymbian OS With ARM Processor
Symbian OS With ARM Processor
alok3089
 
Los Angeles R users group - July 12 2011 - Part 2
Los Angeles R users group - July 12 2011 - Part 2Los Angeles R users group - July 12 2011 - Part 2
Los Angeles R users group - July 12 2011 - Part 2
rusersla
 
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
Eclipse Day India
 
CompletableFuture
CompletableFutureCompletableFuture
CompletableFuture
koji lin
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors Framework
Arun Mehra
 
2013 ARM Student Design Competition @RIT
2013 ARM Student Design Competition @RIT 2013 ARM Student Design Competition @RIT
2013 ARM Student Design Competition @RIT
Antonio Mondragon
 
4th ARM Developer Day Presentation
4th ARM Developer Day Presentation4th ARM Developer Day Presentation
4th ARM Developer Day Presentation
Antonio Mondragon
 
4th ARM Developer Day Presenters info
4th ARM Developer Day Presenters info4th ARM Developer Day Presenters info
4th ARM Developer Day Presenters info
Antonio Mondragon
 
Ad

Similar to Java 8 new features (20)

Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
GlobalLogic Ukraine
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
Jim Bethancourt
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
franciscoortin
 
02basics
02basics02basics
02basics
Waheed Warraich
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
Java 8
Java 8Java 8
Java 8
Sheeban Singaram
 
Unit-3.pptx.pdf java api knowledge apiii
Unit-3.pptx.pdf java api knowledge apiiiUnit-3.pptx.pdf java api knowledge apiii
Unit-3.pptx.pdf java api knowledge apiii
mpfbaa
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
Mario Fusco
 
What's new in c# 8.0
What's new in c# 8.0What's new in c# 8.0
What's new in c# 8.0
Moaid Hathot
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
Rahman USTA
 
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 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
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
jessitron
 
Lambda Functions in Java 8
Lambda Functions in Java 8Lambda Functions in Java 8
Lambda Functions in Java 8
Ganesh Samarthyam
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
Tomasz Kowalczewski
 
Java8.part2
Java8.part2Java8.part2
Java8.part2
Ivan Ivanov
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
Ganesh Samarthyam
 
Java 8 - Lambdas and much more
Java 8 - Lambdas and much moreJava 8 - Lambdas and much more
Java 8 - Lambdas and much more
Alin Pandichi
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Raffi Khatchadourian
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
Maýur Chourasiya
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
franciscoortin
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
Unit-3.pptx.pdf java api knowledge apiii
Unit-3.pptx.pdf java api knowledge apiiiUnit-3.pptx.pdf java api knowledge apiii
Unit-3.pptx.pdf java api knowledge apiii
mpfbaa
 
What's new in c# 8.0
What's new in c# 8.0What's new in c# 8.0
What's new in c# 8.0
Moaid Hathot
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
Rahman USTA
 
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 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
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
jessitron
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
Ganesh Samarthyam
 
Java 8 - Lambdas and much more
Java 8 - Lambdas and much moreJava 8 - Lambdas and much more
Java 8 - Lambdas and much more
Alin Pandichi
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Raffi Khatchadourian
 
Ad

Recently uploaded (20)

World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 

Java 8 new features

  • 1. Java 8 New Features and enhancements Aniket Thakur
  • 2. Interface Basics • What we know so far • What is an interface? • Variables in an interface? • Methods in an interface? • Interface Vrs Abstract class?
  • 3. interface A { void printEmployeeNames(String division); } interface B { void printEmployeeNames(String division); } class AB implements A,B { @Override public void printEmployeeNames(String division) { //print employee names based on division } } public class HelloWorld { public static void main(String args[]) { new AB().printEmployeeNames(”Security"); } } Will this work?
  • 4. Java 8 changes in interface • Static Methods are allowed • Eg. interface A { static void printEmployeeNames(String division) { //print employee names based on division } }
  • 5. Default Methods • Provide default implementation of methods defined in an interface. • Don’t have to make changes in all concrete subclasses implementing the interface Eg – interface A { default void printEmployeeNames(String division) { //print employee names based on division } }
  • 6. interface A { default void printEmployeeNames(String division) { //print employee names based on division } } interface B { default void printEmployeeNames(String division) { //print employee names based on division } } class AB implements A,B { } //make an instance of AB and call printEmployeeNames Will this work?
  • 7. interface A { default void printEmployeeNames(String division) { //print employee names based on division } } interface B { default void printEmployeeNames(String division) { //print employee names based on division } } class AB implements A,B { @Override public void printEmployeeNames(String division) { A.super.printEmployeeNames(division);//whats this? //print employee names based on division } } //make an instance of AB and call printEmployeeNames Will this work?
  • 8. Final local variable(effectively final) public void foo() { final String x = "hello"; String y = "there"; Runnable runnable = new Runnable() { @Override public void run() { System.out.println(x); System.out.println(y); } }; runnable.run(); }
  • 9. Changes in HashMap • Using Balanced trees instead of Linked List • Improves worst case performance from O(n) to O(log n). • Implementation in - • java.util.HashMap, • java.util.LinkedHashMap and • java.util.concurrent.ConcurrentHashMap.
  • 10. Functional Interfaces • Interface with just one abstract method. Eg. – interface MyInterface { int getAge(); } • How about? interface A { boolean equals(Object obj); int getAge(); }
  • 11. How about? interface A { default void printEmployeeNames(String division) {} static void newMethod(){} int getAge(); } • OR interface A { public boolean equals(Object obj); default void printEmployeeNames(String division) {} static void newMethod(){} int getAge(); int getNewAge(); }
  • 12. Seen before? @FunctionalInterface public interface Runnable { public abstract void run(); } OR @FunctionalInterface public interface Comparator<T> { int compare(T o1, T o2); }
  • 13. About Functional interfaces • Any public method defined by Object, any default methods or any static methods do not affect the functional status of an functional interface. As long as it has just one abstract method. • Questions?
  • 14. Common functional interfaces • Part of java.util.function • https://docs.oracle.com/javase/8/docs/api/java/util/function/ package-summary.html • The convention used here us generic type T for type parameter, for second type parameter the next letter U and for a distinct return type R is used as the generic type.
  • 15. Predicate • Takes a single paramter of any type and returns a boolean @FunctionalInterface // what’s this? public interface Predicate<T> { /** * Evaluates this predicate on the given argument. * * @param t the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean test(T t); //other methods }
  • 16. Consumer • Takes a single paramter of any type and has a void return type @FunctionalInterface public interface Consumer<T> { /** * Performs this operation on the given argument. * * @param t the input argument */ void accept(T t); }
  • 17. Supplier • Does not take any parameter and returns any type @FunctionalInterface public interface Supplier<T> { /** * Gets a result. * * @return a result */ T get(); }
  • 18. UnaryOperator • Takes a single parameter of any type and returns of same type @FunctionalInterface public interface Function<T, R> { /** * Applies this function to the given argument. * * @param t the function argument * @return the function result */ R apply(T t); }
  • 20. Lambda Expressions • Lambda expression implements the abstract method in a functional interface. • Kind of anonymous class. Also called closures.
  • 21. Types • Expression Lamdas • Block Lambdas interface MyInterface { boolean isAllowedAge(int currentAge, int minAge); } MyInterface myInterface = (n,m) -> n>=m;//expression System.out.println(myInterface.isAllowedAge(4,5)); MyInterface myInterface = (n,m) -> { //block int minAge = m; if (n >= minAge ) return true; else return false; } System.out.println(myInterface.isAllowedAge(4,5));
  • 22. Similarities n Difference • Block lambdas must have return statements unlike expression ones where RHS is the return value. • We can omit specifying argument types. It is automatically inferred from Functional interface. • You can have local variables, loops , case statement in you block. • Same access rules as inner classes. • Same goes for exception handling. You lambda expression can throw checked exception but so must you abstract method (compatibility). • Eg. Runnable myRunner= () ->{ System.out.println("I am running"); };
  • 23. Power Of Lambda expression • What makes Lambda expressions so special? • Deferred execution • You can now send executable code as method argument. • More later 
  • 24. Say hello to Generics • lambda expression themselves cannot have generics but the functional interface that corresponds to a lambda expression can have generics. Eg. public class HelloWorld { public static void main(String args[]) { MyInterface<String> myStringInterface = (input) -> "Hello " + input; MyInterface<Integer> myIntInterface = (input) -> 10 + input; System.out.println("String based lambda exp : " + myStringInterface.myFunc(”I am Groot")); System.out.println("Integer based labmda exp : " + myIntInterface.myFunc(14)); } } interface MyInterface<T> { T myFunc(T t); }
  • 26. Revisiting common functional interfaces • Predicate : Predicate<String> emptyPredicate = x -> x.isEmpty(); System.out.println(emptyPredicate.test("")); System.out.println(emptyPredicate.test("abc")); • Consumer : Consumer<String> printFunc = x -> System.out.println(x); printFunc.accept("Hello World!"); • Supplier : Supplier<String> strSupplier = () -> "SOME_CONSTANT"; System.out.println(strSupplier.get()); • UnaryOperator UnaryOperator<String> prefixOp = (name) -> "Mr. " + name; System.out.println(prefixOp.apply("Aniket"));
  • 27. Method references • Because Lambda expressions were not enough  • 4 types – • Reference to a static method • Reference to a constructor • Reference to an instance method of an arbitrary object of a particular type • Reference to an instance method of a particular object
  • 28. 1. Reference to a static method List<String> platforms= Arrays.asList(“Android”,”iOS”,”Windows”,”IDontCare”); Consumer<List<String>> methodRef1 = Collections::sort; methodRef1.accept(platforms); System.out.println(platforms); • Equivalent Lambda : Consumer<List<String>> lambdaRef1 = l -> Collections.sort(l);
  • 29. 2. Reference to a constructor Supplier<ArrayList<String>> methodRef2 = ArrayList::new; List<String> newEmployeeNameList = methodRef2.get(); newEmployeeNameList.add(”Intern1"); newEmployeeNameList.add(”Intern2"); System.out.println(newEmployeeNameList); • Equivalent Lambda : Supplier<ArrayList> lambdaRef2 = () -> new ArrayList(); • Advice : Try not to look at LHS for functional interface types and try to guess what kind of interface it is. Coz later we will directly use it in method arguments. More good stuff to follow 
  • 30. 3. Referenceto an instance methodof an arbitraryobjectof a particulartype Predicate<String> methodRef3 = String::isEmpty; String emtptyString = ""; System.out.println(methodRef3.test(emtptyString)); • Equivalent Lambda : Predicate<String> lambdaRef3 = s -> s.isEmpty();
  • 31. 4. Referenceto an instance methodof a particularobject String myName = "Aniket"; Predicate<String> methodRef4 = myName::contains; System.out.println(methodRef4.test("ike")); • Equivalent Lambda : Predicate<String> lambda2 = s -> s.contains(“ike”);
  • 33. Stream API • Basically sequence of data on which you can operate. • Three essential parts – • Source • Think of this as data set used to generate a stream. Depending on this a stream can be • Finite Or • Infinite • Intermediate operations • These operations you can perform on the data set to filter our or process your data. You can use as many as you desire. One intermediate operation will give you stream back so that you can perform additional intermediate operations on it. • Terminal operations • These operations produce final results. Only one terminal operation is allowed per stream.
  • 34. Generating a Stream Stream<String> emptyStream = Stream.empty(); Stream<Integer> singleElementStream = Stream.of(1); Stream<Integer> streamFromArray = Stream.of(1,2,3,4); List<String> listForStream = Arrays.asList("ABC","PQR","XYZ"); Stream<String> streamFromList = listForStream.stream(); //most helpful Stream<Double> randomInfiniteStream = Stream.generate(Math::random); // what’s this? Stream<Integer> sequencedInfiniteStream = Stream.iterate(1, n -> n+1);//what’s this?
  • 35. Operations • Common intermediate operations : • filter() • distinct() • limit() and skip() • map() • sorted() • peek() • Common terminal operations : • allMatch()/anyMatch()/noneMatch() • collect() • count() • findAny()/findFirst() • forEach() • min()/max() • reduce() None of these affect the underlying data set (Unless you do something to change it)
  • 37. Examples! • How about printing a Stream? List<String> listForStream = Arrays.asList("ABC","PQR","XYZ"); Stream<String> streamFromList = listForStream.stream(); //printing using forEach terminal operation streamFromList.forEach(System.out::println); //recreate stream as stream once operated on is invalid streamFromList = listForStream.stream(); //printing using peek intermediate operation streamFromList.peek(System.out::println).count() ; streamFromList = listForStream.stream(); //printing using collect terminal operation System.out.println(streamFromList.collect(Collect ors.toList()));
  • 38. Some more… List<String> listForStream = Arrays.asList(”India", ”USA", ”Russia", ”Iran", ”Italy", ”Iraq", ”Bhutan"); Stream<String> streamFromList = listForStream.stream(); streamFromList .filter(x -> x.startsWith(“I")) .sorted() .limit(3) .forEach(System.out::println);
  • 39. N more… Stream.iterate(1, n -> n+1) .filter(x -> x%5==0) .limit(5) .forEach(System.out::println); Stream.iterate(1, n -> n+1) .filter(x -> x%5==0) .peek(System.out::println) .limit(5) .forEach(System.out::println);
  • 40. java.util.ConcurrentModificationException • Same as iterator do not modify the underlying collection while processing it’s stream. Else you will get - java.util.ConcurrentModificationException • Eg. List<String> listForStream = new ArrayList<>(Arrays.asList("ABC","PQR","XYZ")); Stream<String> streamFromList = listForStream.stream(); streamFromList.forEach(elm -> listForStream.remove(elm));//boom System.out.println(listForStream);
  • 41. Last but not the least • Other topics you can cover on your own 1. Optional class and it’s usage (Specially in Spring MVC) 2. New NIO.2 APIs – Path, Files, walking dir etc. 3. Stream for primitives – IntStream, LongStream, DoubleStream etc 4. Parallel stream – multi threading involved 5. ExecutorService – Callable , Runnable are functional interfaces 6. New Date/Time API
  • 42. Java SE 8 OCP Programmer • If you already have Java 7 certification : • http://education.oracle.com/pls/web_prod-plq- dad/db_pages.getpage?page_id=5001&get_params=p_exam_id: 1Z0-810 • If you have Java 6 or prior certification : • https://education.oracle.com/pls/web_prod-plq- dad/db_pages.getpage?page_id=5001&get_params=p_exam_id: 1Z0-813 • First timers : • You need to give associate level exam first : • https://education.oracle.com/pls/web_prod-plq- dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0- 808 • Then you can give professional once : • https://education.oracle.com/pls/web_prod-plq- dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0- 809