SlideShare a Scribd company logo
JAVA 8 RELEASE (MAR 18, 2014)
Outline
➢ Default Methods (Defender methods)
➢ Lambda expressions
➢ Method references
➢ Functional Interfaces
➢ Stream API (Parallel operations)
➢ Other new features
Functional Interfaces
Interfaces with only one abstract method.
With only one abstract method, these interfaces can be
easily represented with lambda expressions
Example
@FunctionalInterface
public interface SimpleFuncInterface {
public void doWork();
}
Default Methods
In Context of Support For Streams
Java 8 needed to add functionality to existing
Collection interfaces to support Streams (stream(),
forEach())
Default Methods
➢ Pre-Java 8 interfaces couldn’t have method bodies.
➢ The only way to add functionality to Interfaces was to
declare additional methods which would be
implemented in classes that implement the interface.
➢ It is impossible to add methods to an interface without
breaking the existing implementation.
Problem
Default Methods
➢ Default Methods!
➢ Java 8 allows default methods to be added to interfaces
with their full implementation
➢ Classes which implement the interface don’t have to
have implementations of the default method
➢ Allows the addition of functionality to interfaces while
preserving backward compatibility
Solution
Default Methods
public interface A {
default void foo(){
System.out.println("Calling A.foo()");
}
public class Clazz implements A {}
Clazz clazz = new Clazz();
clazz.foo(); // Calling A.foo()
Example
Lambda Expressions
The biggest new feature of Java 8 is language level support for
lambda expressions (Project Lambda).
Java lambda expressions are Java's first step into functional
programming. A Java lambda expression is thus a function
which can be created without belonging to any class.
A lambda expression can be passed around as if it was an
object and executed on demand.
Lambda Expressions
Following are the important characteristics of a lambda
expression
➢ Optional type declaration.
➢ Optional parenthesis around parameter.
➢ Optional curly braces.
➢ Optional return keyword.
Lambda Expressions
➢ With type declaration, MathOperation addition = (int a, int
b) -> a + b;
➢ Without type declaration, MathOperation subtraction = (a,
b) -> a - b;
➢ With return statement along with curly braces,
MathOperation multiplication = (int a, int b) -> { return a * b;
};
➢ Without return statement and without curly braces,
MathOperation division = (int a, int b) -> a / b;
interface MathOperation {
int operation(int a, int b);
}
Lambda Expressions
Example
Runnable task = new Runnable() {
@Override
public void run() {
System.out.println("I am a runnable task");
}
};
task.run();
// Removed boiler plate code using lambda expression
Runnable task = () -> { System.out.println("I am a runnable task");
};
task.run();
Internal vs External
Iteration
// External iteration
List<Integer> numbers = Arrays.asList(20, 40, 50, 100,
4, 3, 2, 6, 8);
for (Integer number : numbers) {
System.out.println(number);
}
// Internal iteration
numbers.forEach(number -> System.out.println(number));
➢ Predicate<T> -> test a property of the object passed as
argument
➢ Consumer<T> -> execute an action on the object
passed as argument
➢ Function<T, U> -> transform a T to a U
➢ BiFunction<T, U, V> -> transform a (T, U) to a V
➢ Supplier<T> -> provide an instance of a T (such as a
factory)
➢ UnaryOperator<T> -> a unary operator from T -> T
➢ BinaryOperator<T> -> a binary operator from (T, T) -> T
Give a look at java.util.function.*
Common JDK8
@FunctionalInterfaces
➢ You use lambda expressions to create anonymous
methods. Method references help to point to methods
by their names. A method reference is described
using :: (double colon) symbol.
➢ You can use replace Lambda Expressions with
Method References where Lambda is invoking
already defined methods.
➢ You can’t pass arguments to methods Reference.
Method references
➢ Reference to a static method
List<Integer> numbers =
Arrays.asList(1,2,3,4,5,6,7,8,9);
numbers .forEach(System .out::println);
➢ Reference to an Instance Method of a Particular Object
class Printer {
void print(Object message) {
System.out.println(message);
}
}
Printer printer = new Printer();
List<Integer> numbers = Arrays.asList(1,2,3,4,5,6,7,8,9);
numbers.forEach(printer ::print);
Method references
➢ Reference to an Instance Method of an Arbitrary Object of
a Particular Type
Integer[] numbers = {5,9,3,4,2,6,1,8,9};
Arrays.sort(numbers, Integer ::compareTo);
➢ Reference to a Constructor
interface StringToChar {
String charToString(char[] values);
}
StringtoChar strChar = String::new;
char[] values = {'J','A','V','A','8'};
System.out.println(strChar .chatToString(values));
Method references
Characteristics of Streams
➢ Streams are not related to InputStreams,
OutputStreams, etc.
➢ Streams are NOT data structures but are wrappers
around Collection that carry values from a source
through a pipeline of operations.
➢ Streams are more powerful, faster and more memory
efficient than Lists
➢ Streams are designed for lambdas
➢ Streams can easily be output as arrays or lists
➢ Streams employ lazy evaluation
➢ Streams are parallelization
➢ Streams can be “on-the-fly”
Creating Streams
➢ From individual values
Stream.of(val1, val2, …)
➢ From array
Stream.of(someArray)
Arrays.stream(someArray)
➢ From List (and other Collections)
someList.stream()
someOtherCollection.stream()
Stream Operations Pipelining
Stream Operations Pipelining
Example
List<Integer> numbers = Arrays.asList(20, 8,
200, 5, 9, 77, 67, 54, 23, 9);
numbers
.stream()
.filter(n -> n % 5 == 0)
.map(n -> n * 2)
.sorted()
.forEach(System .out::println);
Stream laziness
Intermediate & Terminal Operations
Streams – Parallelism for free
Parallelism for free
Other new features
➢ Nashorn, the new JavaScript engine
➢ Date/Time changes (java.time)
➢ Type Annotations (@Nullable, @NonEmpty,
@Readonly etc)
➢ String abc= String.join(" ", "Java", "8");
Thanks!
Any questions?
Ad

More Related Content

What's hot (20)

C standard library functions
C standard library functionsC standard library functions
C standard library functions
Vaishnavee Sharma
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
Murshida ck
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
Sergii Maliarov
 
Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scripts
Ameen San
 
MATLAB Scripts - Examples
MATLAB Scripts - ExamplesMATLAB Scripts - Examples
MATLAB Scripts - Examples
Shameer Ahmed Koya
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8
Dian Aditya
 
java8
java8java8
java8
Arik Abulafya
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
Munsif Ullah
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
sanya6900
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
Mohammed Saleh
 
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 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
 
functions in C
functions in Cfunctions in C
functions in C
Mehwish Mehmood
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
alish sha
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04
IIUM
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
Appili Vamsi Krishna
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
langer4711
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in r
manikanta361
 
Function in C program
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
Vaishnavee Sharma
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
Murshida ck
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
Sergii Maliarov
 
Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scripts
Ameen San
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8
Dian Aditya
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
sanya6900
 
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 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
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
alish sha
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04
IIUM
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
Appili Vamsi Krishna
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
langer4711
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in r
manikanta361
 

Viewers also liked (20)

Diapositivos
DiapositivosDiapositivos
Diapositivos
Laura Ramirez
 
The Added Values and Specific Challenges of a Support Team Composed of Variou...
The Added Values and Specific Challenges of a Support Team Composed of Variou...The Added Values and Specific Challenges of a Support Team Composed of Variou...
The Added Values and Specific Challenges of a Support Team Composed of Variou...
FEANTSA
 
Grupo alberto,johana,paulo,victor,roger esan propuesta 01
Grupo alberto,johana,paulo,victor,roger esan propuesta 01Grupo alberto,johana,paulo,victor,roger esan propuesta 01
Grupo alberto,johana,paulo,victor,roger esan propuesta 01
Johana Sanchez
 
Grupo julio,juan,eduardo,jaime,juan,julio
Grupo julio,juan,eduardo,jaime,juan,julioGrupo julio,juan,eduardo,jaime,juan,julio
Grupo julio,juan,eduardo,jaime,juan,julio
Johana Sanchez
 
Exposicion2
Exposicion2Exposicion2
Exposicion2
SEV
 
Español
EspañolEspañol
Español
Mafevica
 
Servicio comunitario en la una yaracuy..2011 1
Servicio comunitario en la una yaracuy..2011 1Servicio comunitario en la una yaracuy..2011 1
Servicio comunitario en la una yaracuy..2011 1
UNA Centro Local Yaracuy
 
Final slide
Final slideFinal slide
Final slide
Chad Gray
 
Datos Básicos de la Comunidad
Datos Básicos de la ComunidadDatos Básicos de la Comunidad
Datos Básicos de la Comunidad
Laura Ramirez
 
Historieta clásica futuro (copia)
Historieta clásica   futuro (copia) Historieta clásica   futuro (copia)
Historieta clásica futuro (copia)
xochilt Madrid Gonzalez
 
Grupo ana maria,sergio,victor construction sa - normal
Grupo ana maria,sergio,victor   construction sa - normalGrupo ana maria,sergio,victor   construction sa - normal
Grupo ana maria,sergio,victor construction sa - normal
Johana Sanchez
 
Bruk av office 365 i undervisning
Bruk av office 365 i undervisningBruk av office 365 i undervisning
Bruk av office 365 i undervisning
Magnus Nohr
 
POLLOMETRO
POLLOMETROPOLLOMETRO
POLLOMETRO
Laura Ramirez
 
Mi primera comunión
Mi primera comuniónMi primera comunión
Mi primera comunión
Laura Ramirez
 
1 p coa acem-c abreviación 2012
1 p coa acem-c abreviación 20121 p coa acem-c abreviación 2012
1 p coa acem-c abreviación 2012
Herman Van de Velde (ABACOenRed)
 
Son como las weas...
Son como las weas...Son como las weas...
Son como las weas...
Francisco Leal
 
Portfolio Presentation
Portfolio PresentationPortfolio Presentation
Portfolio Presentation
Lori TheStudent
 
13 a jerrodthomas
13 a jerrodthomas13 a jerrodthomas
13 a jerrodthomas
Jerrod Thomas
 
Definiciones
DefinicionesDefiniciones
Definiciones
Laura Ramirez
 
The Added Values and Specific Challenges of a Support Team Composed of Variou...
The Added Values and Specific Challenges of a Support Team Composed of Variou...The Added Values and Specific Challenges of a Support Team Composed of Variou...
The Added Values and Specific Challenges of a Support Team Composed of Variou...
FEANTSA
 
Grupo alberto,johana,paulo,victor,roger esan propuesta 01
Grupo alberto,johana,paulo,victor,roger esan propuesta 01Grupo alberto,johana,paulo,victor,roger esan propuesta 01
Grupo alberto,johana,paulo,victor,roger esan propuesta 01
Johana Sanchez
 
Grupo julio,juan,eduardo,jaime,juan,julio
Grupo julio,juan,eduardo,jaime,juan,julioGrupo julio,juan,eduardo,jaime,juan,julio
Grupo julio,juan,eduardo,jaime,juan,julio
Johana Sanchez
 
Exposicion2
Exposicion2Exposicion2
Exposicion2
SEV
 
Servicio comunitario en la una yaracuy..2011 1
Servicio comunitario en la una yaracuy..2011 1Servicio comunitario en la una yaracuy..2011 1
Servicio comunitario en la una yaracuy..2011 1
UNA Centro Local Yaracuy
 
Datos Básicos de la Comunidad
Datos Básicos de la ComunidadDatos Básicos de la Comunidad
Datos Básicos de la Comunidad
Laura Ramirez
 
Grupo ana maria,sergio,victor construction sa - normal
Grupo ana maria,sergio,victor   construction sa - normalGrupo ana maria,sergio,victor   construction sa - normal
Grupo ana maria,sergio,victor construction sa - normal
Johana Sanchez
 
Bruk av office 365 i undervisning
Bruk av office 365 i undervisningBruk av office 365 i undervisning
Bruk av office 365 i undervisning
Magnus Nohr
 
Mi primera comunión
Mi primera comuniónMi primera comunión
Mi primera comunión
Laura Ramirez
 
Ad

Similar to Java 8 (20)

Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
Aniket Thakur
 
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
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
NexThoughts Technologies
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
GlobalLogic Ukraine
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
franciscoortin
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
Umer Azeem
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
02basics
02basics02basics
02basics
Waheed Warraich
 
Java 8
Java 8Java 8
Java 8
vilniusjug
 
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
 
Java 8
Java 8Java 8
Java 8
AbhimanuHandoo
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
Ayesha Bhatti
 
c & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptxc & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptx
rawatsatish0327
 
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
 
Introduction of function in c programming.pptx
Introduction of function in c programming.pptxIntroduction of function in c programming.pptx
Introduction of function in c programming.pptx
abhajgude
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
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
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
franciscoortin
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
Umer Azeem
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
c & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptxc & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptx
rawatsatish0327
 
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
 
Introduction of function in c programming.pptx
Introduction of function in c programming.pptxIntroduction of function in c programming.pptx
Introduction of function in c programming.pptx
abhajgude
 
Ad

Recently uploaded (20)

How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 

Java 8

  • 1. JAVA 8 RELEASE (MAR 18, 2014)
  • 2. Outline ➢ Default Methods (Defender methods) ➢ Lambda expressions ➢ Method references ➢ Functional Interfaces ➢ Stream API (Parallel operations) ➢ Other new features
  • 3. Functional Interfaces Interfaces with only one abstract method. With only one abstract method, these interfaces can be easily represented with lambda expressions Example @FunctionalInterface public interface SimpleFuncInterface { public void doWork(); }
  • 4. Default Methods In Context of Support For Streams Java 8 needed to add functionality to existing Collection interfaces to support Streams (stream(), forEach())
  • 5. Default Methods ➢ Pre-Java 8 interfaces couldn’t have method bodies. ➢ The only way to add functionality to Interfaces was to declare additional methods which would be implemented in classes that implement the interface. ➢ It is impossible to add methods to an interface without breaking the existing implementation. Problem
  • 6. Default Methods ➢ Default Methods! ➢ Java 8 allows default methods to be added to interfaces with their full implementation ➢ Classes which implement the interface don’t have to have implementations of the default method ➢ Allows the addition of functionality to interfaces while preserving backward compatibility Solution
  • 7. Default Methods public interface A { default void foo(){ System.out.println("Calling A.foo()"); } public class Clazz implements A {} Clazz clazz = new Clazz(); clazz.foo(); // Calling A.foo() Example
  • 8. Lambda Expressions The biggest new feature of Java 8 is language level support for lambda expressions (Project Lambda). Java lambda expressions are Java's first step into functional programming. A Java lambda expression is thus a function which can be created without belonging to any class. A lambda expression can be passed around as if it was an object and executed on demand.
  • 9. Lambda Expressions Following are the important characteristics of a lambda expression ➢ Optional type declaration. ➢ Optional parenthesis around parameter. ➢ Optional curly braces. ➢ Optional return keyword.
  • 10. Lambda Expressions ➢ With type declaration, MathOperation addition = (int a, int b) -> a + b; ➢ Without type declaration, MathOperation subtraction = (a, b) -> a - b; ➢ With return statement along with curly braces, MathOperation multiplication = (int a, int b) -> { return a * b; }; ➢ Without return statement and without curly braces, MathOperation division = (int a, int b) -> a / b; interface MathOperation { int operation(int a, int b); }
  • 11. Lambda Expressions Example Runnable task = new Runnable() { @Override public void run() { System.out.println("I am a runnable task"); } }; task.run(); // Removed boiler plate code using lambda expression Runnable task = () -> { System.out.println("I am a runnable task"); }; task.run();
  • 12. Internal vs External Iteration // External iteration List<Integer> numbers = Arrays.asList(20, 40, 50, 100, 4, 3, 2, 6, 8); for (Integer number : numbers) { System.out.println(number); } // Internal iteration numbers.forEach(number -> System.out.println(number));
  • 13. ➢ Predicate<T> -> test a property of the object passed as argument ➢ Consumer<T> -> execute an action on the object passed as argument ➢ Function<T, U> -> transform a T to a U ➢ BiFunction<T, U, V> -> transform a (T, U) to a V ➢ Supplier<T> -> provide an instance of a T (such as a factory) ➢ UnaryOperator<T> -> a unary operator from T -> T ➢ BinaryOperator<T> -> a binary operator from (T, T) -> T Give a look at java.util.function.* Common JDK8 @FunctionalInterfaces
  • 14. ➢ You use lambda expressions to create anonymous methods. Method references help to point to methods by their names. A method reference is described using :: (double colon) symbol. ➢ You can use replace Lambda Expressions with Method References where Lambda is invoking already defined methods. ➢ You can’t pass arguments to methods Reference. Method references
  • 15. ➢ Reference to a static method List<Integer> numbers = Arrays.asList(1,2,3,4,5,6,7,8,9); numbers .forEach(System .out::println); ➢ Reference to an Instance Method of a Particular Object class Printer { void print(Object message) { System.out.println(message); } } Printer printer = new Printer(); List<Integer> numbers = Arrays.asList(1,2,3,4,5,6,7,8,9); numbers.forEach(printer ::print); Method references
  • 16. ➢ Reference to an Instance Method of an Arbitrary Object of a Particular Type Integer[] numbers = {5,9,3,4,2,6,1,8,9}; Arrays.sort(numbers, Integer ::compareTo); ➢ Reference to a Constructor interface StringToChar { String charToString(char[] values); } StringtoChar strChar = String::new; char[] values = {'J','A','V','A','8'}; System.out.println(strChar .chatToString(values)); Method references
  • 17. Characteristics of Streams ➢ Streams are not related to InputStreams, OutputStreams, etc. ➢ Streams are NOT data structures but are wrappers around Collection that carry values from a source through a pipeline of operations. ➢ Streams are more powerful, faster and more memory efficient than Lists ➢ Streams are designed for lambdas ➢ Streams can easily be output as arrays or lists ➢ Streams employ lazy evaluation ➢ Streams are parallelization ➢ Streams can be “on-the-fly”
  • 18. Creating Streams ➢ From individual values Stream.of(val1, val2, …) ➢ From array Stream.of(someArray) Arrays.stream(someArray) ➢ From List (and other Collections) someList.stream() someOtherCollection.stream()
  • 20. Stream Operations Pipelining Example List<Integer> numbers = Arrays.asList(20, 8, 200, 5, 9, 77, 67, 54, 23, 9); numbers .stream() .filter(n -> n % 5 == 0) .map(n -> n * 2) .sorted() .forEach(System .out::println);
  • 21. Stream laziness Intermediate & Terminal Operations
  • 24. Other new features ➢ Nashorn, the new JavaScript engine ➢ Date/Time changes (java.time) ➢ Type Annotations (@Nullable, @NonEmpty, @Readonly etc) ➢ String abc= String.join(" ", "Java", "8");