SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
Lambdas 
& 
Streams 
In 
JDK8 
Making 
Bulk 
Opera/ons 
Simple 
Simon 
Ri6er 
Head 
of 
Java 
Technology 
Evangelism 
Oracle 
Corp. 
Twi6er: 
@speakjava 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Safe 
Harbor 
Statement 
The 
following 
is 
intended 
to 
outline 
our 
general 
product 
direcTon. 
It 
is 
intended 
for 
informaTon 
purposes 
only, 
and 
may 
not 
be 
incorporated 
into 
any 
contract. 
It 
is 
not 
a 
commitment 
to 
deliver 
any 
material, 
code, 
or 
funcTonality, 
and 
should 
not 
be 
relied 
upon 
in 
making 
purchasing 
decisions. 
The 
development, 
release, 
and 
Tming 
of 
any 
features 
or 
funcTonality 
described 
for 
Oracle’s 
products 
remains 
at 
the 
sole 
discreTon 
of 
Oracle. 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
3
java.util.concurrent 
(jsr166) 
1.0 5.0 6 7 8 
1996 … 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
java.lang.Thread 
Fork/Join 
Framework 
(jsr166y) 
Concurrency 
in 
Java 
Project 
Lambda 
Phasers, 
etc 
(jsr166)
Lambdas 
In 
Java 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
The 
Problem: 
External 
IteraTon 
List<Student> 
students 
= 
... 
double 
highestScore 
= 
0.0; 
for 
(Student 
s 
: 
students) 
{ 
if 
(s.getGradYear() 
== 
2011) 
{ 
if 
(s.getScore() 
> 
highestScore) 
highestScore 
= 
s.score; 
} 
} 
• Our 
code 
controls 
iteraTon 
• Inherently 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
serial: 
iterate 
from 
beginning 
to 
end 
• Not 
thread-­‐safe 
• Business 
logic 
is 
stateful 
• Mutable 
accumulator 
variable
Internal 
IteraTon 
With 
Inner 
Classes 
• IteraTon 
handled 
by 
the 
library 
• Not 
inherently 
serial 
– 
traversal 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
may 
be 
done 
in 
parallel 
• Traversal 
may 
be 
done 
lazily 
– 
so 
one 
pass, 
rather 
than 
three 
• Thread 
safe 
– 
client 
logic 
is 
stateless 
• High 
barrier 
to 
use 
– SyntacTcally 
ugly 
More 
FuncTonal 
double 
highestScore 
= 
students 
.filter(new 
Predicate<Student>() 
{ 
public 
boolean 
op(Student 
s) 
{ 
return 
s.getGradYear() 
== 
2011; 
} 
}) 
.map(new 
Mapper<Student,Double>() 
{ 
public 
Double 
extract(Student 
s) 
{ 
return 
s.getScore(); 
} 
}) 
.max();
Internal 
IteraTon 
With 
Lambdas 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
List<Student> 
students 
= 
... 
double 
highestScore 
= 
students 
.filter(Student 
s 
-­‐> 
s.getGradYear() 
== 
2011) 
.map(Student 
s 
-­‐> 
s.getScore()) 
.max(); 
• More 
readable 
• More 
abstract 
• Less 
error-­‐prone 
NOTE: 
This 
is 
not 
JDK8 
code
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Lambda 
Expressions 
Some 
Details 
• Lambda 
expressions 
represent 
anonymous 
funcTons 
– Same 
structure 
as 
a 
method 
• typed 
argument 
list, 
return 
type, 
set 
of 
thrown 
excepTons, 
and 
a 
body 
– Not 
associated 
with 
a 
class 
• We 
now 
have 
parameterised 
behaviour, 
not 
just 
values 
double 
highestScore 
= 
students. 
filter(Student 
s 
-­‐> 
s.getGradYear() 
== 
2011). 
map(Student 
s 
-­‐> 
s.getScore()) 
max(); 
What 
How
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Lambda 
Expression 
Types 
• Single-­‐method 
interfaces 
are 
used 
extensively 
in 
Java 
– DefiniTon: 
a 
func2onal 
interface 
is 
an 
interface 
with 
one 
abstract 
method 
– Func2onal 
interfaces 
are 
idenTfied 
structurally 
– The 
type 
of 
a 
lambda 
expression 
will 
be 
a 
func2onal 
interface 
• Lambda 
expressions 
provide 
implementaTons 
of 
the 
abstract 
method 
interface 
Comparator<T> 
{ 
boolean 
compare(T 
x, 
T 
y); 
} 
interface 
FileFilter 
{ 
boolean 
accept(File 
x); 
} 
interface 
Runnable 
{ 
void 
run(); 
} 
interface 
ActionListener 
{ 
void 
actionPerformed(…); 
} 
interface 
Callable<T> 
{ 
T 
call(); 
}
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Local 
Variable 
Capture 
• Lambda 
expressions 
can 
refer 
to 
effec2vely 
final 
local 
variables 
from 
the 
enclosing 
scope 
• EffecTvely 
final: 
A 
variable 
that 
meets 
the 
requirements 
for 
final 
variables 
(i.e., 
assigned 
once), 
even 
if 
not 
explicitly 
declared 
final 
• Closures 
on 
values, 
not 
variables 
void 
expire(File 
root, 
long 
before) 
{ 
root.listFiles(File 
p 
-­‐> 
p.lastModified() 
<= 
before); 
}
What 
Does 
‘this’ 
Mean 
For 
Lambdas? 
• ‘this’ 
refers 
to 
the 
enclosing 
object, 
not 
the 
lambda 
itself 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Think 
of 
‘this’ 
as 
a 
final 
predefined 
local 
• Remember 
the 
Lambda 
is 
an 
anonymous 
func2on 
– It 
is 
not 
associated 
with 
a 
class 
– Therefore 
there 
can 
be 
no 
‘this’ 
for 
the 
Lambda
Referencing 
Instance 
Variables 
Which 
are 
not 
final, 
or 
effecTvely 
final 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
class 
DataProcessor 
{ 
private 
int 
currentValue; 
public 
void 
process() 
{ 
DataSet 
myData 
= 
myFactory.getDataSet(); 
dataSet.forEach(d 
-­‐> 
d.use(currentValue++)); 
} 
}
Referencing 
Instance 
Variables 
The 
compiler 
helps 
us 
out 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
class 
DataProcessor 
{ 
private 
int 
currentValue; 
public 
void 
process() 
{ 
DataSet 
myData 
= 
myFactory.getDataSet(); 
dataSet.forEach(d 
-­‐> 
d.use(this.currentValue++); 
} 
} 
‘this’ 
(which 
is 
effecTvely 
final) 
inserted 
by 
the 
compiler
static 
T 
void 
sort(List<T> 
l, 
Comparator<? 
super 
T> 
c); 
List<String> 
list 
= 
getList(); 
Collections.sort(list, 
(String 
x, 
String 
y) 
-­‐> 
x.length() 
-­‐ 
y.length()); 
Collections.sort(list, 
(x, 
y) 
-­‐> 
x.length() 
-­‐ 
y.length()); 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Type 
Inference 
• The 
compiler 
can 
oien 
infer 
parameter 
types 
in 
a 
lambda 
expression 
§ Inferrence 
based 
on 
the 
target 
funcTonal 
interface’s 
method 
signature 
• Fully 
staTcally 
typed 
(no 
dynamic 
typing 
sneaking 
in) 
– More 
typing 
with 
less 
typing
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Method 
References 
• Method 
references 
let 
us 
reuse 
a 
method 
as 
a 
lambda 
expression 
FileFilter 
x 
= 
File 
f 
-­‐> 
f.canRead(); 
FileFilter 
x 
= 
File::canRead;
Factory<List<String>> 
f 
= 
() 
-­‐> 
return 
new 
ArrayList<String>(); 
Replace 
with 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Constructor 
References 
• Same 
concept 
as 
a 
method 
reference 
– For 
the 
constructor 
Factory<List<String>> 
f 
= 
ArrayList<String>::new;
Library 
EvoluTon 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
int 
heaviestBlueBlock 
= 
blocks 
.filter(b 
-­‐> 
b.getColor() 
== 
BLUE) 
.map(Block::getWeight) 
.reduce(0, 
Integer::max); 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Library 
EvoluTon 
Goal 
• Requirement: 
aggregate 
operaTons 
on 
collecTons 
– New 
methods 
required 
on 
CollecTons 
to 
facilitate 
this 
• This 
is 
problemaTc 
– Can’t 
add 
new 
methods 
to 
interfaces 
without 
modifying 
all 
implementaTons 
– Can’t 
necessarily 
find 
or 
control 
all 
implementaTons
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
SoluTon: 
Default 
Methods 
• Specified 
in 
the 
interface 
• From 
the 
caller’s 
perspecTve, 
just 
an 
ordinary 
interface 
method 
• Provides 
a 
default 
implementaTon 
• Default 
only 
used 
when 
implementaTon 
classes 
do 
not 
provide 
a 
body 
for 
the 
extension 
method 
• ImplementaTon 
classes 
can 
provide 
a 
be6er 
version, 
or 
not 
interface 
Collection<E> 
{ 
default 
Stream<E> 
stream() 
{ 
return 
StreamSupport.stream(spliterator()); 
} 
}
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Virtual 
Extension 
Methods 
Stop 
right 
there! 
• Err, 
isn’t 
this 
implemenTng 
mulTple 
inheritance 
for 
Java? 
• Yes, 
but 
Java 
already 
has 
mulTple 
inheritance 
of 
types 
• This 
adds 
mulTple 
inheritance 
of 
behavior 
too 
• But 
not 
state, 
which 
is 
where 
most 
of 
the 
trouble 
is 
• Can 
sTll 
be 
a 
source 
of 
complexity 
• Class 
implements 
two 
interfaces, 
both 
of 
which 
have 
default 
methods 
• Same 
signature 
• How 
does 
the 
compiler 
differenTate? 
• StaTc 
methods 
also 
allowed 
in 
interfaces 
in 
Java 
SE 
8
FuncTonal 
Interface 
DefiniTon 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Single 
Abstract 
Method 
(SAM) 
type 
• A 
funcTonal 
interface 
is 
an 
interface 
that 
has 
one 
abstract 
method 
– Represents 
a 
single 
funcTon 
contract 
– Doesn’t 
mean 
it 
only 
has 
one 
method 
• @FunctionalInterface 
annotaTon 
– Helps 
ensure 
the 
funcTonal 
interface 
contract 
is 
honoured 
– Compiler 
error 
if 
not 
a 
SAM
Lambdas 
In 
Full 
Flow: 
Streams 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Aggregate 
OperaTons 
• Most 
business 
logic 
is 
about 
aggregate 
operaTons 
– “Most 
profitable 
product 
by 
region” 
– “Group 
transacTons 
by 
currency” 
• As 
we 
have 
seen, 
up 
to 
now, 
Java 
uses 
external 
iteraTon 
– Inherently 
serial 
– FrustraTngly 
imperaTve 
• Java 
SE 
8’s 
answer: 
The 
Stream 
API 
– With 
help 
from 
Lambdas
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Stream 
Overview 
At 
The 
High 
Level 
• AbstracTon 
for 
specifying 
aggregate 
computaTons 
– Not 
a 
data 
structure 
– Can 
be 
infinite 
• Simplifies 
the 
descripTon 
of 
aggregate 
computaTons 
– Exposes 
opportuniTes 
for 
opTmisaTon 
– Fusing, 
laziness 
and 
parallelism
Source 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Stream 
Overview 
• A 
stream 
pipeline 
consists 
of 
three 
types 
of 
things 
– A 
source 
– Zero 
or 
more 
intermediate 
operaTons 
– A 
terminal 
operaTon 
• Producing 
a 
result 
or 
a 
side-­‐effect 
Pipeline 
int 
total 
= 
transactions.stream() 
.filter(t 
-­‐> 
t.getBuyer().getCity().equals(“London”)) 
.mapToInt(Transaction::getPrice) 
.sum(); 
Intermediate 
operaTon 
Terminal 
operaTon
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Stream 
Sources 
Many 
Ways 
To 
Create 
• From 
collecTons 
and 
arrays 
– Collection.stream() 
– Collection.parallelStream() 
– Arrays.stream(T 
array) 
or 
Stream.of() 
• StaTc 
factories 
– IntStream.range() 
– Files.walk() 
• Roll 
your 
own 
– java.util.Spliterator
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Stream 
Sources 
Provide 
• Access 
to 
stream 
elements 
• DecomposiTon 
(for 
parallel 
operaTons) 
– Fork-­‐join 
framework 
• Stream 
characterisTcs 
– ORDERED 
– SORTED 
– DISTINCT 
– SIZED 
– NONNULL 
– IMMUTABLE 
– CONCURRENT
Stream 
Terminal 
OperaTons 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• The 
pipeline 
is 
only 
evaluated 
when 
the 
terminal 
operaTon 
is 
called 
– All 
operaTons 
can 
execute 
sequenTally 
or 
in 
parallel 
– Intermediate 
operaTons 
can 
be 
merged 
• Avoiding 
mulTple 
redundant 
passes 
on 
data 
• Short-­‐circuit 
operaTons 
(e.g. 
findFirst) 
• Lazy 
evaluaTon 
– Stream 
characterisTcs 
help 
idenTfy 
opTmisaTons 
• DISTINT 
stream 
passed 
to 
distinct() 
is 
a 
no-­‐op
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Maps 
and 
FlatMaps 
Map 
Values 
in 
a 
Stream 
Map 
FlatMap 
Input 
Stream 
Input 
Stream 
1-­‐to-­‐1 
mapping 
1-­‐to-­‐many 
mapping 
Output 
Stream 
Output 
Stream
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Optional<T> 
Reducing 
NullPointerException 
Occurrences 
String 
direction 
= 
gpsData.getPosition().getLatitude().getDirection(); 
String 
direction 
= 
“UNKNOWN”; 
if 
(gpsData 
!= 
null) 
{ 
Position 
p 
= 
gpsData.getPosition(); 
if 
(p 
!= 
null) 
{ 
Latitude 
latitude 
= 
p.getLatitude(); 
if 
(latitude 
!= 
null) 
direction 
= 
latitude.getDirection(); 
} 
}
NullPointerException 
Occurrences 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Optional<T> 
Reducing 
• Indicates 
that 
reference 
may, 
or 
may 
not 
have 
a 
value 
– Makes 
developer 
responsible 
for 
checking 
– A 
bit 
like 
a 
stream 
that 
can 
only 
have 
zero 
or 
one 
elements 
Optional<GPSData> 
maybeGPS 
= 
Optional.ofNullable(gpsData); 
maybeGPS.ifPresent(GPSData::printPosition); 
GPSData 
gps 
= 
maybeGPS.orElse(new 
GPSData()); 
maybeGPS.filter(g 
-­‐> 
g.lastRead() 
< 
2).ifPresent(GPSData.display());
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Example 
1 
Convert 
words 
in 
list 
to 
upper 
case 
List<String> 
output 
= 
wordList 
.stream() 
.map(String::toUpperCase) 
.collect(Collectors.toList());
Example 
1 
Convert 
words 
in 
list 
to 
upper 
case 
(in 
parallel) 
List<String> 
output 
= 
wordList 
.parallelStream() 
.map(String::toUpperCase) 
.collect(Collectors.toList()); 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Example 
2 
• BufferedReader 
has 
new 
method 
– Stream<String> 
lines() 
Count 
lines 
in 
a 
file 
long 
count 
= 
bufferedReader 
.lines() 
.count();
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Example 
3 
Join 
lines 
3-­‐4 
into 
a 
single 
string 
String 
output 
= 
bufferedReader 
.lines() 
.skip(2) 
.limit(2) 
.collect(Collectors.joining());
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Example 
4 
Collect 
all 
words 
in 
a 
file 
into 
a 
list 
List<String> 
output 
= 
reader 
.lines() 
.flatMap(line 
-­‐> 
Stream.of(line.split(REGEXP))) 
.filter(word 
-­‐> 
word.length() 
> 
0) 
.collect(Collectors.toList());
Example 
5 
List 
of 
unique 
words 
in 
lowercase, 
sorted 
by 
length 
List<String> 
output 
= 
reader 
.lines() 
.flatMap(line 
-­‐> 
Stream.of(line.split(REGEXP))) 
.filter(word 
-­‐> 
word.length() 
> 
0) 
.map(String::toLowerCase) 
.distinct() 
.sorted((x, 
y) 
-­‐> 
x.length() 
-­‐ 
y.length()) 
.collect(Collectors.toList()); 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Example 
6: 
Real 
World 
Infinite 
stream 
from 
thermal 
sensor 
private 
int 
double 
currentTemperature; 
... 
thermalReader 
.lines() 
.mapToDouble(s 
-­‐> 
Double.parseDouble(s.substring(0, 
s.length() 
-­‐ 
1))) 
.map(t 
-­‐> 
((t 
– 
32) 
* 
5 
/ 
9) 
.filter(t 
-­‐> 
t 
!= 
currentTemperature) 
.peek(t 
-­‐> 
listener.ifPresent(l 
-­‐> 
l.temperatureChanged(t))) 
.forEach(t 
-­‐> 
currentTemperature 
= 
t); 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Example 
6: 
Real 
World 
Infinite 
stream 
from 
thermal 
sensor 
private 
int 
double 
currentTemperature; 
... 
thermalReader 
.lines() 
.mapToDouble(s 
-­‐> 
Double.parseDouble(s.substring(0, 
s.length() 
-­‐ 
))) 
.map(t 
-­‐> 
((t 
– 
32) 
* 
5 
/ 
9) 
.filter(t 
-­‐> 
t 
!= 
this.currentTemperature) 
.peek(t 
-­‐> 
listener.ifPresent(l 
-­‐> 
l.temperatureChanged(t))) 
.forEach(t 
-­‐> 
this.currentTemperature 
= 
t); 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Conclusions 
• Java 
needs 
lambda 
statements 
– Significant 
improvements 
in 
exisTng 
libraries 
are 
required 
• Require 
a 
mechanism 
for 
interface 
evoluTon 
– SoluTon: 
virtual 
extension 
methods 
• Bulk 
operaTons 
on 
CollecTons 
– Much 
simpler 
with 
Lambdas 
• Java 
SE 
8 
evolves 
the 
language, 
libraries, 
and 
VM 
together
Simon 
Ri6er 
Oracle 
CorporarTon 
Twi6er: 
@speakjava 
Copyright 
Š 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.

Weitere ähnliche Inhalte

Was ist angesagt?

Lambdas Hands On Lab
Lambdas Hands On LabLambdas Hands On Lab
Lambdas Hands On LabSimon Ritter
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterSimon Ritter
 
Lessons Learnt With Lambdas and Streams in JDK 8
Lessons Learnt With Lambdas and Streams in JDK 8Lessons Learnt With Lambdas and Streams in JDK 8
Lessons Learnt With Lambdas and Streams in JDK 8Simon Ritter
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New FeaturesNaveen Hegde
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & StreamsC4Media
 
java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8Tobias Coetzee
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features OverviewSergii Stets
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambdaManav Prasad
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8Takipi
 
Java8 features
Java8 featuresJava8 features
Java8 featuresElias Hasnat
 
java programming - applets
java programming - appletsjava programming - applets
java programming - appletsHarshithaAllu
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigoujaxconf
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streamsManav Prasad
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 featuresSanjoy Kumar Roy
 

Was ist angesagt? (20)

Lambdas Hands On Lab
Lambdas Hands On LabLambdas Hands On Lab
Lambdas Hands On Lab
 
Apouc 2014-java-8-create-the-future
Apouc 2014-java-8-create-the-futureApouc 2014-java-8-create-the-future
Apouc 2014-java-8-create-the-future
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritter
 
Lessons Learnt With Lambdas and Streams in JDK 8
Lessons Learnt With Lambdas and Streams in JDK 8Lessons Learnt With Lambdas and Streams in JDK 8
Lessons Learnt With Lambdas and Streams in JDK 8
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & Streams
 
Java 8
Java 8Java 8
Java 8
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Chap1java5th
Chap1java5thChap1java5th
Chap1java5th
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 

Ähnlich wie Lambdas And Streams in JDK8

What's New in Java 8
What's New in Java 8What's New in Java 8
What's New in Java 8javafxpert
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...jaxLondonConference
 
JShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java PlatformJShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java PlatformJavaDayUA
 
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
 
Interactive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and ArchitectureInteractive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and ArchitectureJavaDayUA
 
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 InterfacesRaffi Khatchadourian
 
Servlet 4.0 Adopt-a-JSR 10 Minute Infodeck
Servlet 4.0 Adopt-a-JSR 10 Minute InfodeckServlet 4.0 Adopt-a-JSR 10 Minute Infodeck
Servlet 4.0 Adopt-a-JSR 10 Minute InfodeckEdward Burns
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature PreviewJim Bethancourt
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 OverviewNicola Pedot
 
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...AMD Developer Central
 
Java 8
Java 8Java 8
Java 8jclingan
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8jclingan
 
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 8Simon Ritter
 
JDK 10 Java Module System
JDK 10 Java Module SystemJDK 10 Java Module System
JDK 10 Java Module SystemWolfgang Weigend
 
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)
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, androidi i
 
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]David Buck
 

Ähnlich wie Lambdas And Streams in JDK8 (20)

What's New in Java 8
What's New in Java 8What's New in Java 8
What's New in Java 8
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
 
JShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java PlatformJShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java Platform
 
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...
 
Interactive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and ArchitectureInteractive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and Architecture
 
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
 
Servlet 4.0 Adopt-a-JSR 10 Minute Infodeck
Servlet 4.0 Adopt-a-JSR 10 Minute InfodeckServlet 4.0 Adopt-a-JSR 10 Minute Infodeck
Servlet 4.0 Adopt-a-JSR 10 Minute Infodeck
 
JDK8 Streams
JDK8 StreamsJDK8 Streams
JDK8 Streams
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Completable future
Completable futureCompletable future
Completable future
 
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
 
Java 8
Java 8Java 8
Java 8
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8
 
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
 
Core java
Core javaCore java
Core java
 
JDK 10 Java Module System
JDK 10 Java Module SystemJDK 10 Java Module System
JDK 10 Java Module System
 
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
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
 
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
 

Mehr von Simon Ritter

Cloud Native Compiler
Cloud Native CompilerCloud Native Compiler
Cloud Native CompilerSimon Ritter
 
Java On CRaC
Java On CRaCJava On CRaC
Java On CRaCSimon Ritter
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type PatternsSimon Ritter
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon Ritter
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoringSimon Ritter
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon Ritter
 
Getting the Most From Modern Java
Getting the Most From Modern JavaGetting the Most From Modern Java
Getting the Most From Modern JavaSimon Ritter
 
Building a Better JVM
Building a Better JVMBuilding a Better JVM
Building a Better JVMSimon Ritter
 
JDK 14 Lots of New Features
JDK 14 Lots of New FeaturesJDK 14 Lots of New Features
JDK 14 Lots of New FeaturesSimon Ritter
 
Java after 8
Java after 8Java after 8
Java after 8Simon Ritter
 
How to Choose a JDK
How to Choose a JDKHow to Choose a JDK
How to Choose a JDKSimon Ritter
 
Java Programming
Java ProgrammingJava Programming
Java ProgrammingSimon Ritter
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
Developing Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologyDeveloping Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologySimon Ritter
 
Is Java Still Free?
Is Java Still Free?Is Java Still Free?
Is Java Still Free?Simon Ritter
 
Moving Towards JDK 12
Moving Towards JDK 12Moving Towards JDK 12
Moving Towards JDK 12Simon Ritter
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondSimon Ritter
 
Java Is Still Free
Java Is Still FreeJava Is Still Free
Java Is Still FreeSimon Ritter
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondSimon Ritter
 
JDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveJDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveSimon Ritter
 

Mehr von Simon Ritter (20)

Cloud Native Compiler
Cloud Native CompilerCloud Native Compiler
Cloud Native Compiler
 
Java On CRaC
Java On CRaCJava On CRaC
Java On CRaC
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoring
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
Getting the Most From Modern Java
Getting the Most From Modern JavaGetting the Most From Modern Java
Getting the Most From Modern Java
 
Building a Better JVM
Building a Better JVMBuilding a Better JVM
Building a Better JVM
 
JDK 14 Lots of New Features
JDK 14 Lots of New FeaturesJDK 14 Lots of New Features
JDK 14 Lots of New Features
 
Java after 8
Java after 8Java after 8
Java after 8
 
How to Choose a JDK
How to Choose a JDKHow to Choose a JDK
How to Choose a JDK
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Developing Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologyDeveloping Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java Technology
 
Is Java Still Free?
Is Java Still Free?Is Java Still Free?
Is Java Still Free?
 
Moving Towards JDK 12
Moving Towards JDK 12Moving Towards JDK 12
Moving Towards JDK 12
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and Beyond
 
Java Is Still Free
Java Is Still FreeJava Is Still Free
Java Is Still Free
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and Beyond
 
JDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveJDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep Dive
 

KĂźrzlich hochgeladen

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy LĂłpez
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 

KĂźrzlich hochgeladen (20)

Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 

Lambdas And Streams in JDK8

  • 1.
  • 2. Lambdas & Streams In JDK8 Making Bulk Opera/ons Simple Simon Ri6er Head of Java Technology Evangelism Oracle Corp. Twi6er: @speakjava Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.
  • 3. Safe Harbor Statement The following is intended to outline our general product direcTon. It is intended for informaTon purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or funcTonality, and should not be relied upon in making purchasing decisions. The development, release, and Tming of any features or funcTonality described for Oracle’s products remains at the sole discreTon of Oracle. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. 3
  • 4. java.util.concurrent (jsr166) 1.0 5.0 6 7 8 1996 … 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. java.lang.Thread Fork/Join Framework (jsr166y) Concurrency in Java Project Lambda Phasers, etc (jsr166)
  • 5. Lambdas In Java Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.
  • 6. The Problem: External IteraTon List<Student> students = ... double highestScore = 0.0; for (Student s : students) { if (s.getGradYear() == 2011) { if (s.getScore() > highestScore) highestScore = s.score; } } • Our code controls iteraTon • Inherently Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. serial: iterate from beginning to end • Not thread-­‐safe • Business logic is stateful • Mutable accumulator variable
  • 7. Internal IteraTon With Inner Classes • IteraTon handled by the library • Not inherently serial – traversal Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. may be done in parallel • Traversal may be done lazily – so one pass, rather than three • Thread safe – client logic is stateless • High barrier to use – SyntacTcally ugly More FuncTonal double highestScore = students .filter(new Predicate<Student>() { public boolean op(Student s) { return s.getGradYear() == 2011; } }) .map(new Mapper<Student,Double>() { public Double extract(Student s) { return s.getScore(); } }) .max();
  • 8. Internal IteraTon With Lambdas Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. List<Student> students = ... double highestScore = students .filter(Student s -­‐> s.getGradYear() == 2011) .map(Student s -­‐> s.getScore()) .max(); • More readable • More abstract • Less error-­‐prone NOTE: This is not JDK8 code
  • 9. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Lambda Expressions Some Details • Lambda expressions represent anonymous funcTons – Same structure as a method • typed argument list, return type, set of thrown excepTons, and a body – Not associated with a class • We now have parameterised behaviour, not just values double highestScore = students. filter(Student s -­‐> s.getGradYear() == 2011). map(Student s -­‐> s.getScore()) max(); What How
  • 10. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Lambda Expression Types • Single-­‐method interfaces are used extensively in Java – DefiniTon: a func2onal interface is an interface with one abstract method – Func2onal interfaces are idenTfied structurally – The type of a lambda expression will be a func2onal interface • Lambda expressions provide implementaTons of the abstract method interface Comparator<T> { boolean compare(T x, T y); } interface FileFilter { boolean accept(File x); } interface Runnable { void run(); } interface ActionListener { void actionPerformed(…); } interface Callable<T> { T call(); }
  • 11. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Local Variable Capture • Lambda expressions can refer to effec2vely final local variables from the enclosing scope • EffecTvely final: A variable that meets the requirements for final variables (i.e., assigned once), even if not explicitly declared final • Closures on values, not variables void expire(File root, long before) { root.listFiles(File p -­‐> p.lastModified() <= before); }
  • 12. What Does ‘this’ Mean For Lambdas? • ‘this’ refers to the enclosing object, not the lambda itself Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. • Think of ‘this’ as a final predefined local • Remember the Lambda is an anonymous func2on – It is not associated with a class – Therefore there can be no ‘this’ for the Lambda
  • 13. Referencing Instance Variables Which are not final, or effecTvely final Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. class DataProcessor { private int currentValue; public void process() { DataSet myData = myFactory.getDataSet(); dataSet.forEach(d -­‐> d.use(currentValue++)); } }
  • 14. Referencing Instance Variables The compiler helps us out Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. class DataProcessor { private int currentValue; public void process() { DataSet myData = myFactory.getDataSet(); dataSet.forEach(d -­‐> d.use(this.currentValue++); } } ‘this’ (which is effecTvely final) inserted by the compiler
  • 15. static T void sort(List<T> l, Comparator<? super T> c); List<String> list = getList(); Collections.sort(list, (String x, String y) -­‐> x.length() -­‐ y.length()); Collections.sort(list, (x, y) -­‐> x.length() -­‐ y.length()); Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Type Inference • The compiler can oien infer parameter types in a lambda expression § Inferrence based on the target funcTonal interface’s method signature • Fully staTcally typed (no dynamic typing sneaking in) – More typing with less typing
  • 16. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Method References • Method references let us reuse a method as a lambda expression FileFilter x = File f -­‐> f.canRead(); FileFilter x = File::canRead;
  • 17. Factory<List<String>> f = () -­‐> return new ArrayList<String>(); Replace with Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Constructor References • Same concept as a method reference – For the constructor Factory<List<String>> f = ArrayList<String>::new;
  • 18. Library EvoluTon Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.
  • 19. int heaviestBlueBlock = blocks .filter(b -­‐> b.getColor() == BLUE) .map(Block::getWeight) .reduce(0, Integer::max); Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Library EvoluTon Goal • Requirement: aggregate operaTons on collecTons – New methods required on CollecTons to facilitate this • This is problemaTc – Can’t add new methods to interfaces without modifying all implementaTons – Can’t necessarily find or control all implementaTons
  • 20. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. SoluTon: Default Methods • Specified in the interface • From the caller’s perspecTve, just an ordinary interface method • Provides a default implementaTon • Default only used when implementaTon classes do not provide a body for the extension method • ImplementaTon classes can provide a be6er version, or not interface Collection<E> { default Stream<E> stream() { return StreamSupport.stream(spliterator()); } }
  • 21. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Virtual Extension Methods Stop right there! • Err, isn’t this implemenTng mulTple inheritance for Java? • Yes, but Java already has mulTple inheritance of types • This adds mulTple inheritance of behavior too • But not state, which is where most of the trouble is • Can sTll be a source of complexity • Class implements two interfaces, both of which have default methods • Same signature • How does the compiler differenTate? • StaTc methods also allowed in interfaces in Java SE 8
  • 22. FuncTonal Interface DefiniTon Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. • Single Abstract Method (SAM) type • A funcTonal interface is an interface that has one abstract method – Represents a single funcTon contract – Doesn’t mean it only has one method • @FunctionalInterface annotaTon – Helps ensure the funcTonal interface contract is honoured – Compiler error if not a SAM
  • 23. Lambdas In Full Flow: Streams Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.
  • 24. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Aggregate OperaTons • Most business logic is about aggregate operaTons – “Most profitable product by region” – “Group transacTons by currency” • As we have seen, up to now, Java uses external iteraTon – Inherently serial – FrustraTngly imperaTve • Java SE 8’s answer: The Stream API – With help from Lambdas
  • 25. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Stream Overview At The High Level • AbstracTon for specifying aggregate computaTons – Not a data structure – Can be infinite • Simplifies the descripTon of aggregate computaTons – Exposes opportuniTes for opTmisaTon – Fusing, laziness and parallelism
  • 26. Source Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Stream Overview • A stream pipeline consists of three types of things – A source – Zero or more intermediate operaTons – A terminal operaTon • Producing a result or a side-­‐effect Pipeline int total = transactions.stream() .filter(t -­‐> t.getBuyer().getCity().equals(“London”)) .mapToInt(Transaction::getPrice) .sum(); Intermediate operaTon Terminal operaTon
  • 27. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Stream Sources Many Ways To Create • From collecTons and arrays – Collection.stream() – Collection.parallelStream() – Arrays.stream(T array) or Stream.of() • StaTc factories – IntStream.range() – Files.walk() • Roll your own – java.util.Spliterator
  • 28. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Stream Sources Provide • Access to stream elements • DecomposiTon (for parallel operaTons) – Fork-­‐join framework • Stream characterisTcs – ORDERED – SORTED – DISTINCT – SIZED – NONNULL – IMMUTABLE – CONCURRENT
  • 29. Stream Terminal OperaTons Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. • The pipeline is only evaluated when the terminal operaTon is called – All operaTons can execute sequenTally or in parallel – Intermediate operaTons can be merged • Avoiding mulTple redundant passes on data • Short-­‐circuit operaTons (e.g. findFirst) • Lazy evaluaTon – Stream characterisTcs help idenTfy opTmisaTons • DISTINT stream passed to distinct() is a no-­‐op
  • 30. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Maps and FlatMaps Map Values in a Stream Map FlatMap Input Stream Input Stream 1-­‐to-­‐1 mapping 1-­‐to-­‐many mapping Output Stream Output Stream
  • 31. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Optional<T> Reducing NullPointerException Occurrences String direction = gpsData.getPosition().getLatitude().getDirection(); String direction = “UNKNOWN”; if (gpsData != null) { Position p = gpsData.getPosition(); if (p != null) { Latitude latitude = p.getLatitude(); if (latitude != null) direction = latitude.getDirection(); } }
  • 32. NullPointerException Occurrences Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Optional<T> Reducing • Indicates that reference may, or may not have a value – Makes developer responsible for checking – A bit like a stream that can only have zero or one elements Optional<GPSData> maybeGPS = Optional.ofNullable(gpsData); maybeGPS.ifPresent(GPSData::printPosition); GPSData gps = maybeGPS.orElse(new GPSData()); maybeGPS.filter(g -­‐> g.lastRead() < 2).ifPresent(GPSData.display());
  • 33. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Example 1 Convert words in list to upper case List<String> output = wordList .stream() .map(String::toUpperCase) .collect(Collectors.toList());
  • 34. Example 1 Convert words in list to upper case (in parallel) List<String> output = wordList .parallelStream() .map(String::toUpperCase) .collect(Collectors.toList()); Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.
  • 35. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Example 2 • BufferedReader has new method – Stream<String> lines() Count lines in a file long count = bufferedReader .lines() .count();
  • 36. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Example 3 Join lines 3-­‐4 into a single string String output = bufferedReader .lines() .skip(2) .limit(2) .collect(Collectors.joining());
  • 37. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Example 4 Collect all words in a file into a list List<String> output = reader .lines() .flatMap(line -­‐> Stream.of(line.split(REGEXP))) .filter(word -­‐> word.length() > 0) .collect(Collectors.toList());
  • 38. Example 5 List of unique words in lowercase, sorted by length List<String> output = reader .lines() .flatMap(line -­‐> Stream.of(line.split(REGEXP))) .filter(word -­‐> word.length() > 0) .map(String::toLowerCase) .distinct() .sorted((x, y) -­‐> x.length() -­‐ y.length()) .collect(Collectors.toList()); Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.
  • 39. Example 6: Real World Infinite stream from thermal sensor private int double currentTemperature; ... thermalReader .lines() .mapToDouble(s -­‐> Double.parseDouble(s.substring(0, s.length() -­‐ 1))) .map(t -­‐> ((t – 32) * 5 / 9) .filter(t -­‐> t != currentTemperature) .peek(t -­‐> listener.ifPresent(l -­‐> l.temperatureChanged(t))) .forEach(t -­‐> currentTemperature = t); Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.
  • 40. Example 6: Real World Infinite stream from thermal sensor private int double currentTemperature; ... thermalReader .lines() .mapToDouble(s -­‐> Double.parseDouble(s.substring(0, s.length() -­‐ ))) .map(t -­‐> ((t – 32) * 5 / 9) .filter(t -­‐> t != this.currentTemperature) .peek(t -­‐> listener.ifPresent(l -­‐> l.temperatureChanged(t))) .forEach(t -­‐> this.currentTemperature = t); Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.
  • 41. Copyright Š 2014, Oracle and/or its affiliates. All rights reserved. Conclusions • Java needs lambda statements – Significant improvements in exisTng libraries are required • Require a mechanism for interface evoluTon – SoluTon: virtual extension methods • Bulk operaTons on CollecTons – Much simpler with Lambdas • Java SE 8 evolves the language, libraries, and VM together
  • 42. Simon Ri6er Oracle CorporarTon Twi6er: @speakjava Copyright Š 2014, Oracle and/or its affiliates. All rights reserved.