SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Mohamed Ben Hassine
Java / JEE Technical Lead
Trainer
med.ingenieur@gmail.com
(+216) 52 633 220
www.linkedin.com/in/mohamedbnhassine
Java 8 Bootcamp
Java 8 Bootcamp
What you will Learn
• Get Started
• Lambda Expressions
• Java 8 Stream API
• New Date and Time API
• Nashorn: New JavaScript Engine
• Miscellaneous
LAMBDA EXPRESSION
History of Java releases
4
1995
JDKIntroduction
January1996
JDK1.0
“OAK”JDK1.0
December1998
J2SE1.2
FoundationofJCJ
Swing,Collections
February2002
J2SE1.4
Assert,JAXP,IPv6
RegularExpressions
February 1997
JDK 1.1
Java Beans, RMI , JDBC,
JIT
May 2000
J2SE 1.3
HotSpot JVM , JNDI,
Java Debugger
September 2004
J2SE 5.0
Generics, Metadata,
Concurrency, Static
Import
September 2006
Java SE 6
Java Compiler API
,Support JDBC 4.0 , JVM
improvements
July 2011
Java SE 7
Try-with-Resources
Strings in switch
New IO API , Dynamic
languages
March 2015
Java SE 8
Project Lambda Streams
API , Functional Interfaces
,Nashorn Engine ,New
Date Time API ,
Annotations on Type
2017
Java SE 9
Jshell Java REPL ,
Support HTTP 2.0 , G1
default Garbage
Collector
Get Started
Why Java 8 Now ?
5
Get Started
Revolution in Processing power
Parallel multicores architectures
Big Data Applications
Code behavior
Code as data
Functional programming Support
Enhance core librairies
Interface unlocking (concrete methods )
Backward compatibility
Java / Javascript
JavaScript made great in Java 8
Install and configure Java 8
6
Get Started
Project Based Course
7
Get Started
Employee management
Throughout the whole course , we will develop a java
console app which offers suck key features :
 Add manage employee
 Manage employees personal details , salaries and bonus
 Search employee by predefined criteria
Lambda Expressions
First Lambda Expression
Comparator<Employee> compLambda = ( emp1, emp2) -> {
int i = Integer.compare(emp1.getAge(), emp2.getAge());
if (i != 0) {
return i;
} else {
i = Double.compare(emp1.getSalary(), emp2.getSalary());
if (i != 0)
return i;
}
return i;
};
Collections.sort(persons, compLambda);
Much Easier !
persons.sort(Comparator.comparing(Employee::getAge).thenComparing(Employee::getSalary));
Don’t worry about this code for now. This
Course will explain what it does and how you can develop
similar code!
Lambda Expressions
Why Lambda Expression
 Using anonymous classes for code behavior parameterization is verbose
 Programmers struggle with anonymous classes.
(confusion “this”, no access to non-final local variables)
 Convenient for new streams library
persons.forEach(emp -> emp.setSalary(3000));
Solution :
Lambda let you represent a behavior or pass code in a concise way.
Another way to write anonymous classes
Comparator<Employee> compLambda = ( emp1, emp2) -> { return emp1.getJobTitle().compareTo(emp2.getJobTitle()); }
Lambda
Parameters
Arrow
Lambda Body
Lambda Expressions
How to Write Lambda Expression
The simple way
More than One line of code
Runnable r = () -> {
for (int i = 0; i < 2016; i++) {
System.out.println("Hello to your Java SE 8 Bootcamp 2016 !");
}
};
More than One Argument
Comparator<Employee> compLambda = (Employee emp1, Employee emp2) -> {
return emp1.getJobTitle().compareTo(emp2.getJobTitle());
}
;
FileFilter filter = (File file) -> file.getName().endsWith("class");
Lambda Expressions
So what is exactly Lambda Expression ?
Everything in Java has a type so what for Lambda ? :
Lambda Expression is Functional Interface ( new Java 8 concept , Interface with one
abstract Method..example Runnable , Comparator interfaces known prior to Java
SE8 as Single Abstract Method Interface).
Where to use A Lambda Expression ?
In each case it could be assigned to a variable of Type Functional Interface
Runnable r = () -> System.out.println("Hello to your Java SE 8 Bootcamp 2016 !");
;
Lambda Expression
Lambda Expressions
Functional Interface
An Interface with only one abstract method
Example :
public interface Runnable {
public abstract void run();
}
@FunctionalInterface
public interface SimpleInterface {
public void doSomeJob() ;
}
Define Java SE8 Functional Interface
Lambda Expressions
Predefined Functional Interface in JAVA SE8
New Java Package : java.util.function
Divided into 4 categories :
Supplier Consumer Predicate
/** @since 1.8
*/
@FunctionalInterface
public interface
Supplier<T> {
/**
* Gets a result.
*
* @return a result
*/
T get();
}
Function
/** @since 1.8
*/
@FunctionalInterface
public interface Consumer<T>
{
/**
* @param t the input
argument
*/
void accept(T t);
}
/** @since 1.8
*/
@FunctionalInterface
public interface
Predicate<T> {
/**
* Evaluates this
predicate on the given
argument.
*/
boolean test(T t);
}
/** @since 1.8
*/
@FunctionalInterface
public interface Function<T,
R> {
/**
* Applies this function
to the given argument.
*/
R apply(T t);
}
Lambda Expressions
Method Reference
Simply : An other way to write Lambda Expression
Comparator<Employee> compLambda = (Employee emp1, Employee emp2) -> {
return Double.compare(emp1.getSalary(), emp2.getSalary()) ;
}
;
Comparator<Employee> compLambdaRef = Comparator.comparing(Employee::getSalary);
– Replace
(args) -> ClassName.staticMethodName(args)
– with
ClassName::staticMethodName
Lambda Expressions
So how to process Data with this Lambda ?
List<Employee> persons = new ArrayList<>();
persons.add(new Employee("Mohamed", 30, 2500, new Date(), true, "Java / JEE TL"));
persons.add(new Employee("Ferdaous", 24, 1900, new Date(), false, "IT Consultant"));
// Prior to Java SE 8
for (Employee employee : persons) { System.out.println(employee) ;}
Using Lambda Expression
// Traverse collection with Lambda Expression
persons.forEach(emp -> System.out.println(emp));
// More concise syntax with Method Reference
persons.forEach(System.out::println);
Where does this method come from ? All interface
implementations of Iterable should be refactored !..
Response Next episode ..
Lambda Expressions
Default Method
In Java 8 a method can be implemented in an interface.
 New Java 8 Concept for backward compatibility
Allow to add methods to an existing interface long after it has been released
without breaking the interface
Interface
void newMethod()
Class
implements
Compilation Error must
implement newMethod
Solution to not modify sub class
Interface
default void
newMethod() {
Code here….
}
Does not break any sub
class implementing this
Interface
 Default Method could be overridden in interface implementation
Lambda Expressions
Interface Static Method
Similar to default methods except that it is not possible to override them in
the implementation classes
providing security.
Interface static methods are good for providing utility methods.
Interface
void newMethod()
Class
implements
Compilation Error must
implement newMethod
Solution to not modify sub class
Interface
Static void
newMethod() {
Code here….
}
Does not break any sub
class implementing this
Interface
JAVA 8 STREAM API
JAVA 8 Stream API
What’s Stream API
Coming Soon 

Weitere ähnliche Inhalte

Was ist angesagt?

Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript FundamentalsSrdjan Strbanovic
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Knoldus Inc.
 
JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional APIJustin Lin
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8Dinesh Pathak
 
Intro to Java 8 Closures (Dainius Mezanskas)
Intro to Java 8 Closures (Dainius Mezanskas)Intro to Java 8 Closures (Dainius Mezanskas)
Intro to Java 8 Closures (Dainius Mezanskas)Kaunas Java User Group
 
Python Lambda Function
Python Lambda FunctionPython Lambda Function
Python Lambda FunctionMd Soyaib
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdasshinolajla
 
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 OverviewEclipse Day India
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scalaStratio
 
Refactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapRefactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapDave Orme
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async LibraryKnoldus Inc.
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaDerek Chen-Becker
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala languageAaqib Pervaiz
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008maximgrp
 

Was ist angesagt? (20)

Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
 
JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
 
Intro to Java 8 Closures (Dainius Mezanskas)
Intro to Java 8 Closures (Dainius Mezanskas)Intro to Java 8 Closures (Dainius Mezanskas)
Intro to Java 8 Closures (Dainius Mezanskas)
 
Python Lambda Function
Python Lambda FunctionPython Lambda Function
Python Lambda Function
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Functional java 8
Functional java 8Functional java 8
Functional java 8
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
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
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 
Refactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapRefactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 Recap
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to Scala
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala language
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008
 

Ähnlich wie Java 8 Bootcamp

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 singhHarmeet Singh(Taara)
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8 Dori Waldman
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesRaimonds Simanovskis
 
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 StreamsEmiel Paasschens
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8Dian Aditya
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalUrs Peter
 
Extending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsExtending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsRaimonds Simanovskis
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern JavaSina Madani
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신Sungchul Park
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentationVan Huong
 
Java- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solutionJava- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solutionMazenetsolution
 

Ähnlich wie Java 8 Bootcamp (20)

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 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
 
Free your lambdas
Free your lambdasFree your lambdas
Free your lambdas
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
 
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
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_final
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Extending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsExtending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on Rails
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern Java
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Java- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solutionJava- Updates in java8-Mazenet solution
Java- Updates in java8-Mazenet solution
 
Oracle adapters for Ruby ORMs
Oracle adapters for Ruby ORMsOracle adapters for Ruby ORMs
Oracle adapters for Ruby ORMs
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 

Mehr von Mohamed Ben Hassine (6)

Agile_Team
Agile_TeamAgile_Team
Agile_Team
 
togaf
togaftogaf
togaf
 
scrum_certificate
scrum_certificatescrum_certificate
scrum_certificate
 
Udemy_BigData
Udemy_BigDataUdemy_BigData
Udemy_BigData
 
Mohamed -CV 2016
Mohamed -CV 2016 Mohamed -CV 2016
Mohamed -CV 2016
 
My CV 2016
My CV 2016My CV 2016
My CV 2016
 

Java 8 Bootcamp

  • 1. Mohamed Ben Hassine Java / JEE Technical Lead Trainer med.ingenieur@gmail.com (+216) 52 633 220 www.linkedin.com/in/mohamedbnhassine Java 8 Bootcamp
  • 2. Java 8 Bootcamp What you will Learn • Get Started • Lambda Expressions • Java 8 Stream API • New Date and Time API • Nashorn: New JavaScript Engine • Miscellaneous
  • 4. History of Java releases 4 1995 JDKIntroduction January1996 JDK1.0 “OAK”JDK1.0 December1998 J2SE1.2 FoundationofJCJ Swing,Collections February2002 J2SE1.4 Assert,JAXP,IPv6 RegularExpressions February 1997 JDK 1.1 Java Beans, RMI , JDBC, JIT May 2000 J2SE 1.3 HotSpot JVM , JNDI, Java Debugger September 2004 J2SE 5.0 Generics, Metadata, Concurrency, Static Import September 2006 Java SE 6 Java Compiler API ,Support JDBC 4.0 , JVM improvements July 2011 Java SE 7 Try-with-Resources Strings in switch New IO API , Dynamic languages March 2015 Java SE 8 Project Lambda Streams API , Functional Interfaces ,Nashorn Engine ,New Date Time API , Annotations on Type 2017 Java SE 9 Jshell Java REPL , Support HTTP 2.0 , G1 default Garbage Collector Get Started
  • 5. Why Java 8 Now ? 5 Get Started Revolution in Processing power Parallel multicores architectures Big Data Applications Code behavior Code as data Functional programming Support Enhance core librairies Interface unlocking (concrete methods ) Backward compatibility Java / Javascript JavaScript made great in Java 8
  • 6. Install and configure Java 8 6 Get Started
  • 7. Project Based Course 7 Get Started Employee management Throughout the whole course , we will develop a java console app which offers suck key features :  Add manage employee  Manage employees personal details , salaries and bonus  Search employee by predefined criteria
  • 8. Lambda Expressions First Lambda Expression Comparator<Employee> compLambda = ( emp1, emp2) -> { int i = Integer.compare(emp1.getAge(), emp2.getAge()); if (i != 0) { return i; } else { i = Double.compare(emp1.getSalary(), emp2.getSalary()); if (i != 0) return i; } return i; }; Collections.sort(persons, compLambda); Much Easier ! persons.sort(Comparator.comparing(Employee::getAge).thenComparing(Employee::getSalary)); Don’t worry about this code for now. This Course will explain what it does and how you can develop similar code!
  • 9. Lambda Expressions Why Lambda Expression  Using anonymous classes for code behavior parameterization is verbose  Programmers struggle with anonymous classes. (confusion “this”, no access to non-final local variables)  Convenient for new streams library persons.forEach(emp -> emp.setSalary(3000)); Solution : Lambda let you represent a behavior or pass code in a concise way. Another way to write anonymous classes Comparator<Employee> compLambda = ( emp1, emp2) -> { return emp1.getJobTitle().compareTo(emp2.getJobTitle()); } Lambda Parameters Arrow Lambda Body
  • 10. Lambda Expressions How to Write Lambda Expression The simple way More than One line of code Runnable r = () -> { for (int i = 0; i < 2016; i++) { System.out.println("Hello to your Java SE 8 Bootcamp 2016 !"); } }; More than One Argument Comparator<Employee> compLambda = (Employee emp1, Employee emp2) -> { return emp1.getJobTitle().compareTo(emp2.getJobTitle()); } ; FileFilter filter = (File file) -> file.getName().endsWith("class");
  • 11. Lambda Expressions So what is exactly Lambda Expression ? Everything in Java has a type so what for Lambda ? : Lambda Expression is Functional Interface ( new Java 8 concept , Interface with one abstract Method..example Runnable , Comparator interfaces known prior to Java SE8 as Single Abstract Method Interface). Where to use A Lambda Expression ? In each case it could be assigned to a variable of Type Functional Interface Runnable r = () -> System.out.println("Hello to your Java SE 8 Bootcamp 2016 !"); ; Lambda Expression
  • 12. Lambda Expressions Functional Interface An Interface with only one abstract method Example : public interface Runnable { public abstract void run(); } @FunctionalInterface public interface SimpleInterface { public void doSomeJob() ; } Define Java SE8 Functional Interface
  • 13. Lambda Expressions Predefined Functional Interface in JAVA SE8 New Java Package : java.util.function Divided into 4 categories : Supplier Consumer Predicate /** @since 1.8 */ @FunctionalInterface public interface Supplier<T> { /** * Gets a result. * * @return a result */ T get(); } Function /** @since 1.8 */ @FunctionalInterface public interface Consumer<T> { /** * @param t the input argument */ void accept(T t); } /** @since 1.8 */ @FunctionalInterface public interface Predicate<T> { /** * Evaluates this predicate on the given argument. */ boolean test(T t); } /** @since 1.8 */ @FunctionalInterface public interface Function<T, R> { /** * Applies this function to the given argument. */ R apply(T t); }
  • 14. Lambda Expressions Method Reference Simply : An other way to write Lambda Expression Comparator<Employee> compLambda = (Employee emp1, Employee emp2) -> { return Double.compare(emp1.getSalary(), emp2.getSalary()) ; } ; Comparator<Employee> compLambdaRef = Comparator.comparing(Employee::getSalary); – Replace (args) -> ClassName.staticMethodName(args) – with ClassName::staticMethodName
  • 15. Lambda Expressions So how to process Data with this Lambda ? List<Employee> persons = new ArrayList<>(); persons.add(new Employee("Mohamed", 30, 2500, new Date(), true, "Java / JEE TL")); persons.add(new Employee("Ferdaous", 24, 1900, new Date(), false, "IT Consultant")); // Prior to Java SE 8 for (Employee employee : persons) { System.out.println(employee) ;} Using Lambda Expression // Traverse collection with Lambda Expression persons.forEach(emp -> System.out.println(emp)); // More concise syntax with Method Reference persons.forEach(System.out::println); Where does this method come from ? All interface implementations of Iterable should be refactored !.. Response Next episode ..
  • 16. Lambda Expressions Default Method In Java 8 a method can be implemented in an interface.  New Java 8 Concept for backward compatibility Allow to add methods to an existing interface long after it has been released without breaking the interface Interface void newMethod() Class implements Compilation Error must implement newMethod Solution to not modify sub class Interface default void newMethod() { Code here…. } Does not break any sub class implementing this Interface  Default Method could be overridden in interface implementation
  • 17. Lambda Expressions Interface Static Method Similar to default methods except that it is not possible to override them in the implementation classes providing security. Interface static methods are good for providing utility methods. Interface void newMethod() Class implements Compilation Error must implement newMethod Solution to not modify sub class Interface Static void newMethod() { Code here…. } Does not break any sub class implementing this Interface
  • 19. JAVA 8 Stream API What’s Stream API Coming Soon 