SlideShare a Scribd company logo
What`s New in Java 8
Mohsen Zainalpour
zainalpour@yahoo.com

JUG
JDK 8
Schedule and status
•
•
•
•
•
•
•
•
•
•

2012/04/26
2012/06/14
2012/08/02
2012/09/13
2012/11/29
2013/01/31
2013/06/13
2013/09/05
2014/01/23
2014/03/18

M1
M2
M3
M4
M5
M6
M7 Feature Complete
M8 Developer Preview
M9 Final Release Candidate
GA General Availability
Agenda
Major changes

1

Why is Java still changing?

2

Lambda Project

3

Date and Time API

4

Type Annotations

5

Compact Profiles

JUG
Java 8 Is Revolutionary, Java Is Back

“Lambda is the single largest upgrade to the programming
model. Ever. It's larger even than Generics. It's the first time
since the beginning of Java that we've done a carefully
coordinated co-evolution of the virtual machine, the language
and the libraries, all together. Yet the result still feels like
Java. Mark Reinhold (Chief Architect of the Java Platform Group at Oracle)
Java 8 Is Revolutionary, Java Is Back

“Lambda is the single largest upgrade to the programming
model. Ever. It's larger even than Generics. It's the first time
since the beginning of Java that we've done a carefully
coordinated co-evolution of the virtual machine, the language
and the libraries, all together. Yet the result still feels like
Java. Mark Reinhold (Chief Architect of the Java Platform Group at Oracle)
Lambda
JSR 335
Why is Java still changing?
Why is Java still changing?
Why is Java still changing?
Why is Java still changing?
Why is Java still changing?
Why is Java still changing?
Why is Java still changing?
Why is Java still changing?
The changing computing background

big data

multicore

cloud
computing

Increasingly dealing with big data (terabytes and up) and wishing to exploit
multicore computers or computing clusters effectively to process this.
And this means using:

parallel processing
The Progress of Programming

There`s been a lot of progress

&
Progress is being allowed to forget things!
The Progress of Programming
There`s been a lot of progress:

- Assemblers let us forget opcodes
The Progress of Programming
There`s been a lot of progress:

- Assemblers let us forget opcodes
- Garbage collections let us forget memory management
#include <stdio.h>
#include <stdlib.h>
int main () {
…
buffer = (char*) malloc (i+1);
…
free (buffer);
…
}
The Progress of Programming

So what about parallelism?
Why Can`t We Forget About Parallelism?
Most of parallelism problems are doing bulk operations on
collection
and we keep writing code like this:

int sum = 0;
for (int i = 0; i < a.length; i++) {
sum += a[i];
}

It is inherently serial
Why Can`t We Forget About Parallelism?

If the processing of different elements is to proceed in
parallel, it is the responsibility of the client code
Why Can`t We Forget About Parallelism?
If the processing of different elements is to proceed in parallel, it is the responsibility
of the client code

n1

n2

n3

sum1

n4

n5

n6

n7

sum2

n8

n9

…

…

sum3

…

…

sum4
Why Can`t We Forget About Parallelism?
If the processing of different elements is to proceed in parallel, it is the responsibility
of the client code

n1

n2

n3

sum1

n4

n5

n6

n7

sum2

n8

n9

…

…

…

…

sum3

class Sum implements Callable<Long> {
private final long from;
private final long to;
Sum(long from, long to) {
this.from = from;
this.to = to;
}
public Long call() {
long acc = 0;
for (long i = from; i <= to; i++) {
acc = acc + i;
}
return acc;
}
}

sum4
Why Can`t We Forget About Parallelism?
If the processing of different elements is to proceed in parallel, it is the responsibility
of the client code

n1

n2

n3

sum1

n4

n5

n6

n7

sum2

n8

n9

…

…

sum3

…

…

sum4

ExecutorService executor = Executors.newFixedThreadPool(2);
List<Future<Long>> results = executor.invokeAll(asList(
new Sum(1,
250),
new Sum(251, 500),
new Sum(551, 750),
new Sum(751, 1000)
));
for (Future<Long> result : results) {
System.out.println(result.get());
}
Why Can`t We Forget About Parallelism?
Sequential

Thread 1

Parallel
(assuming a
quad core
machine)

Thread 1
Thread 2
Thread 3
Thread 4

Time t

Done
parallel

Done
sequential
Why Can`t We Forget About Parallelism?
Let the Library Writers do it!

Collection developers know the recursive structure of their data
But right now they can`t use that knowledge
Why Can`t We Forget About Parallelism?
Let the Library Writers do it!

Collection developers know the recursive structure of their data
But right now they can`t use that knowledge
int sum = 0;

for (Iterator<Integer> itr = myList.iterator();itr.hasNext(); ) {
sum += itr.next();
}

The problem is external iteration
Why Can`t We Forget About Parallelism?
Internal Iteration
Instead of this:
int sum = 0;
for (int i=0;i<myList.size();i++){
int a=myList.get(i);
sum+=a;
}
Why Can`t We Forget About Parallelism?
Internal Iteration
Instead of this:

We`re going to write this:

int sum = 0;

int [] sum = new int[1];

for (int i=0;i<myList.size();i++){
int a=myList.get(i);
sum+=a;
}

myList.forEach(
…
);
Why Can`t We Forget About Parallelism?
Internal Iteration
Instead of this:

We`re going to write this:

int sum = 0;

int [] sum = new int[1];

for (int i=0;i<myList.size();i++){
int a=myList.get(i);
sum+=a;
}

myList.forEach(
…
);

• Let the collection choose its iteration strategy
- Parallel, serial, out-of-order, lazy, …
Why Can`t We Forget About Parallelism?
Internal Iteration
Instead of this:

We`re going to write this:

int sum = 0;

int [] sum = new int[1];

for (int i=0;i<myList.size();i++){
int a=myList.get(i);
sum+=a;
}

myList.forEach(
a -> sum[0]+=a
);

• Let the collection choose its iteration strategy
- Parallel, serial, out-of-order, lazy, …
Why Can`t We Forget About Parallelism?

a ->

sum[0]+=a
Lambda Project – JSR 335

JSR 335 (Lambda Project) aims to support
programming in a
multicore environment
by adding closures and related features to
the Java language.
What are Lambda Expressions (closures)?
A lambda expression :
What are Lambda Expressions (closures)?
A lambda expression :

is an
anonymous
method
What are Lambda Expressions (closures)?
A lambda expression :

is an
anonymous
method

a ->

having an
argument
list
What are Lambda Expressions (closures)?
A lambda expression :

is an
anonymous
method

a return
type

a ->

having an
argument
list
What are Lambda Expressions (closures)?
A lambda expression :

is an
anonymous
method

a return
type

a ->

having an
argument
list

and a body

sum[0]+=a
What are Lambda Expressions (closures)?
A lambda expression :

is an
anonymous
method

having an
argument
list

a return
type

and a body

and able to refer to values from the enclosing scope (closure)
a ->

sum[0]+=a
What are Lambda Expressions (closures)?
A lambda expression :

is an
anonymous
method

having an
argument
list

To pass behavior to the API as data
a return
type

and a body

and able to refer to values from the enclosing scope (closure)
a ->

sum[0]+=a
From Single Method Interface ….
public interface Comparator<T> {
}
From Single Method Interface ….
public interface Comparator<T> {
int compare(T o1, T o2);
}
From Single Method Interface ….
public interface Comparator<T> {
int compare(T o1, T o2); Single Abstract Method (SAM)
}
From Single Method Interface ….
public interface Comparator<T> {
int compare(T o1, T o2); Single Abstract Method (SAM)
}

Functional Interface
From Single Method Interface ….
public interface Comparator<T> {
int compare(T o1, T o2);
}
Collections.sort(strings, new Comparator<String>()
{
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
From Single Method Interface ….
public interface Comparator<T> {
int compare(T o1, T o2);
}
Collections.sort(strings, new Comparator<String>()
{
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
From Single Method Interface ….
public interface Comparator<T> {
int compare(T o1, T o2);
}
Collections.sort(strings, new Comparator<String>()
{
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
 Bulky syntax
 Confusion surrounding the meaning of names and this
… To Lambda Expressions
Collections.sort(strings, (s1, s2) -> s1.compareToIgnoreCase(s2));
… To Lambda Expressions
Collections.sort(strings, (s1, s2) -> s1.compareToIgnoreCase(s2));
… To Lambda Expressions
Collections.sort(strings, (s1, s2) -> s1.compareToIgnoreCase(s2));
Lambda expression are always converted to
instance of a functional interface

Comparator<String> c = (s1, s2) -> s1.compareToIgnoreCase(s2));
No need of changing the JVM to create a new
type for lambda expressions
… To Lambda Expressions

Collections.sort(strings,
new Comparator<String>() {
public int
compare(String s1, String s2)
{
return
s1.compareToIgnoreCase(s2);
}
});

Collections.sort(strings,
(s1, s2) ->
s1.compareToIgnoreCase(s2)
);
… To Lambda Expressions

Collections.sort(strings,
new Comparator<String>() {
public int
compare(String s1, String s2)
{
return
s1.compareToIgnoreCase(s2);
}
});

Collections.sort(strings,
(s1, s2) ->
s1.compareToIgnoreCase(s2)
);
Without more language support
for parallel idioms,
people will instinctively reach for
serial idioms
External Iteration
Sum of squares

long sum = 0L;
for (long i = 0; i < N; i++) {
sum += i * i;
}
Internal Iteration
Sum of squares

long sum = LongStream.range(0, N)
.map(i -> i * i)
.sum();
Internal Iteration
Going parallel

long sum = LongStream.range(0, N)
.parallel()
.map(i -> i * i)
.sum();
Parallel Streams
A behavioral parameter (lambda) may be invoked concurrently
– This constraint gives us “wiggle room” to optimize
Up the level of abstraction
External iteration conflates what with how
Internal iteration: more what; less how
Client passes behavior to the API as data
Library is free to use
Multiple
threads

Out-oforder
execution

Laziness
Lambdas in Java 8
Code as
data
(Simplicity)

Bulk data
operations

Lambda
Interface
evolution

Multi-core
processing
/ parallel
processing
Lambdas in Java 8
Date and Time API
JSR 310
New Date and Time API
History of Java Date/Time APIs

Java.util.Date, java.util.Calendar
- Strong candidates for the all-time worst Java platform library
design
Joda Time
- Quality date and time library
JSR-310
- Builds on experience of Joda Time
New Date and Time API
Design Principles

Immutable
- Thread-safe, allows caching
Fluent
- easy to read, like a DSL
LocalDate.of(2013,Month.JANUARY,09).withYear(2014);
New Date and Time API
Time for Humans

Field-base, designed for humans
- Year,month,day,hour,minute,second
- LocalDate,LocalDateTime,ZonedDateTime,Period …
New Date and Time API

Los Angeles
16:20
London
12:50
New Date and Time API
void flightTime()
{
LocalDate date = LocalDate.of(2013, Month.SEPTEMBER, 14);
LocalTime takeoff = LocalTime.of(12, 50);
LocalTime landing = LocalTime.of(16, 20);
ZoneId LHR = ZoneId.of("Europe/London");
ZoneId SFO = ZoneId.of("America/Los_Angeles");
Duration flightTime = Duration.between(
ZonedDateTime.of(date, takeoff, LHR),
ZonedDateTime.of(date, landing, SFO));
System.out.println("Flight time: " + flightTime);
}
Annotations
JSR 308
Type Annotations
 JSR-308 brings annotations on Type use
 Are an enabler for the checkers framework

Ex.:
new @Interned MyObject();
myString = (@NonNull String) myObject;
void monitorTemperature() throws
@Critical TemperatureException { ... }
Repeating Annotations
 Before
@Schedules ({
@Schedule(dayOfMonth="Last"),
@Schedule(dayOfWeek="Fri", hour="23")
)}
public void doPeriodicCleanup() { ... }
Repeating Annotations
 Before
@Schedules ({
@Schedule(dayOfMonth="Last"),
@Schedule(dayOfWeek="Fri", hour="23")
)}
public void doPeriodicCleanup() { ... }

 After
@Schedule(dayOfMonth="Last”)
@Schedule(dayOfWeek="Fri", hour="23")
public void doPeriodicCleanup() { ... }
Java SE 8 Compact Profiles
Java SE 8 Compact Profiles

SE 8 Compact
Profiles
3

SE Full JRE

Optional Components

UI & Toolkits

2

Compact3 Class libraries

Integration Libraries

Compact2 Class libraries

Other Base Libraries

Base Compact1 Classes

Lang & Util Base Libraries

Hotspot VM

Hotspot VM

1
Q&A
References
• Lambda
http://stackoverflow.com/questions/220658/what-is-the-difference-between-a-closure-and-a-lambda
http://openjdk.java.net/projects/lambda/
http://jcp.org/aboutJava/communityprocess/edr/jsr335/index2.html
http://vimeo.com/48577033 (slides: http://www.slideshare.net/tkowalcz/java-gets-a-closure)
http://datumedge.blogspot.co.uk/2012/06/java-8-lambdas.html
http://www.theserverside.com/news/thread.tss?thread_id=68718
http://medianetwork.oracle.com/video/player/1785479333001
https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=6080
https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=5089
http://www.lektorium.tv/lecture/?id=14048
http://www.lektorium.tv/lecture/?id=14049
http://blog.xebia.com/2012/11/05/report-will-java-8s-lambda-change-the-face-of-the-world/
http://www.slideshare.net/fsarradin/java-8-lambda
http://programmers.stackexchange.com/questions/173441/what-triggered-the-popularity-of-lambda-functions-in-modernmainstream-programmi?newsletter=1&nlcode=29983%
7c903a
http://www.slideshare.net/bje/java-closures
* Collections
http://www.javabeat.net/2012/05/enhanced-collections-api-in-java-8-supports-lambda-expressions/
http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html
http://architects.dzone.com/articles/java-collections-api
References
• Remove the Permanent Generation
http://www.cubrid.org/blog/dev-platform/understanding-jvm-internals/
http://javaeesupportpatterns.blogspot.com/2011/10/java-7-features-permgen-removal.html
http://java.dzone.com/articles/busting-permgen-myths
https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=5135
• JSR 310: Date and Time API
http://java.dzone.com/articles/introducing-new-date-and-time
http://sourceforge.net/apps/mediawiki/threeten/index.php?title=ThreeTen
http://www.infoq.com/news/2010/03/jsr-310
https://docs.google.com/document/pub?id=1rd8yplQZIRz3LxMzpVLuskr1b0HwBmK9PXpdgBYojSw
http://sourceforge.net/apps/mediawiki/threeten/index.php?title=User_Guide
https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=4350
• General Java8
http://openjdk.java.net/projects/jdk8/features
http://www.pcadvisor.co.uk/news/software/3401314/oracle-java-upgrades-still-worthwhile-despite-postponed-features/
http://dhruba.name/2011/07/06/oracle-discusses-java-7-8-new-features-on-video/
http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012/Java-8
http://www.parleys.com/#st=5&id=2850&sl=1
http://www.parleys.com/#st=5&id=2847
https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=2872
https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=10458
References
• Annotations
https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=4469
https://blogs.oracle.com/abuckley/entry/jsr_308_moves_forward
http://jcp.org/en/jsr/detail?id=308
http://openjdk.java.net/jeps/120
http://types.cs.washington.edu/checker-framework/
Ad

More Related Content

What's hot (11)

Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
Stratio
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas
shinolajla
 
Kotlin Crash Course
Kotlin Crash CourseKotlin Crash Course
Kotlin Crash Course
Haim Michael
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
Knoldus Inc.
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
Martin Odersky
 
Functional Programming in Scala
Functional Programming in ScalaFunctional Programming in Scala
Functional Programming in Scala
Bassam Abd El Hameed
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Syntactic Salt and Sugar Presentation
Syntactic Salt and Sugar PresentationSyntactic Salt and Sugar Presentation
Syntactic Salt and Sugar Presentation
grepalex
 
Aggregate Programming in Scala
Aggregate Programming in ScalaAggregate Programming in Scala
Aggregate Programming in Scala
Roberto Casadei
 
Java 8 stream and c# 3.5
Java 8 stream and c# 3.5Java 8 stream and c# 3.5
Java 8 stream and c# 3.5
Quang Trần Duy
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
Stratio
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas
shinolajla
 
Kotlin Crash Course
Kotlin Crash CourseKotlin Crash Course
Kotlin Crash Course
Haim Michael
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
Knoldus Inc.
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
Martin Odersky
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Syntactic Salt and Sugar Presentation
Syntactic Salt and Sugar PresentationSyntactic Salt and Sugar Presentation
Syntactic Salt and Sugar Presentation
grepalex
 
Aggregate Programming in Scala
Aggregate Programming in ScalaAggregate Programming in Scala
Aggregate Programming in Scala
Roberto Casadei
 

Viewers also liked (20)

Hacking_PPT
Hacking_PPT Hacking_PPT
Hacking_PPT
Gaurav Gautam
 
Skyworth
SkyworthSkyworth
Skyworth
TELE-satellite esp
 
Appcelerator Alloy MVC
Appcelerator Alloy MVCAppcelerator Alloy MVC
Appcelerator Alloy MVC
Fokke Zandbergen
 
MIT Article October 2006
MIT Article October 2006MIT Article October 2006
MIT Article October 2006
Patrick Byrne
 
TSS intro slides general
TSS intro slides generalTSS intro slides general
TSS intro slides general
Science City Bristol
 
Port Android To Windows App
Port Android To Windows AppPort Android To Windows App
Port Android To Windows App
Cheah Eng Soon
 
Tell-n-sell April 30 to May 06
Tell-n-sell April 30 to May 06Tell-n-sell April 30 to May 06
Tell-n-sell April 30 to May 06
nelsonprada123
 
fra TELE-satellite-1107
fra TELE-satellite-1107fra TELE-satellite-1107
fra TELE-satellite-1107
TELE-satellite fra
 
The Seer - By Orson Pratt
The Seer - By Orson PrattThe Seer - By Orson Pratt
The Seer - By Orson Pratt
David Marques
 
X path
X pathX path
X path
Sagar Guhe
 
por TELE-satellite-1107
por TELE-satellite-1107por TELE-satellite-1107
por TELE-satellite-1107
TELE-satellite por
 
R57shell
R57shellR57shell
R57shell
ady36
 
Load
LoadLoad
Load
grateful7
 
Dr.eduardo apresentaçao
Dr.eduardo apresentaçaoDr.eduardo apresentaçao
Dr.eduardo apresentaçao
NEG'S Desarrollo de Sitios Web
 
Crisis or Opportunity
Crisis or OpportunityCrisis or Opportunity
Crisis or Opportunity
Diane Hillmann
 
The Theme Of Scat
The Theme Of ScatThe Theme Of Scat
The Theme Of Scat
Michelle Carraway
 
가상화와 보안 발표자료
가상화와 보안 발표자료가상화와 보안 발표자료
가상화와 보안 발표자료
hanbeom Park
 
Wordpress 3.5 -install-appserv
Wordpress 3.5 -install-appservWordpress 3.5 -install-appserv
Wordpress 3.5 -install-appserv
Boonlert Aroonpiboon
 
Programming Without Coding Technology (PWCT) Features - Framework & Extension
Programming Without Coding Technology (PWCT) Features - Framework & ExtensionProgramming Without Coding Technology (PWCT) Features - Framework & Extension
Programming Without Coding Technology (PWCT) Features - Framework & Extension
Mahmoud Samir Fayed
 
Teste
TesteTeste
Teste
guestd3fca5
 
Ad

Similar to What`s New in Java 8 (20)

Java 8-revealed
Java 8-revealedJava 8-revealed
Java 8-revealed
Hamed Hatami
 
Java 8
Java 8Java 8
Java 8
vilniusjug
 
Google Interview Questions By Scholarhat
Google Interview Questions By ScholarhatGoogle Interview Questions By Scholarhat
Google Interview Questions By Scholarhat
Scholarhat
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
Viplav Jain
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
Harmeet Singh(Taara)
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
François Sarradin
 
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
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
AboutYouGmbH
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
Nayden Gochev
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
jeffz
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
James Long
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
IndicThreads
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
stasimus
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
Narendran Solai Sridharan
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
Ahmed mar3y
 
Lambdas
LambdasLambdas
Lambdas
malliksunkara
 
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
 
Introduction to meta-programming in scala
Introduction to meta-programming in scalaIntroduction to meta-programming in scala
Introduction to meta-programming in scala
Alessandro Marrella
 
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3
Simon Ritter
 
Google Interview Questions By Scholarhat
Google Interview Questions By ScholarhatGoogle Interview Questions By Scholarhat
Google Interview Questions By Scholarhat
Scholarhat
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
Viplav Jain
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
Harmeet Singh(Taara)
 
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
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
AboutYouGmbH
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
Nayden Gochev
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
jeffz
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
James Long
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
IndicThreads
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
stasimus
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
Ahmed mar3y
 
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
 
Introduction to meta-programming in scala
Introduction to meta-programming in scalaIntroduction to meta-programming in scala
Introduction to meta-programming in scala
Alessandro Marrella
 
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3
Simon Ritter
 
Ad

Recently uploaded (20)

Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
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
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
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
 
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
 
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
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
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
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
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
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
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
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
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
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
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
 
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
 
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
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
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
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
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
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
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
 

What`s New in Java 8

  • 1. What`s New in Java 8 Mohsen Zainalpour [email protected] JUG
  • 2. JDK 8 Schedule and status • • • • • • • • • • 2012/04/26 2012/06/14 2012/08/02 2012/09/13 2012/11/29 2013/01/31 2013/06/13 2013/09/05 2014/01/23 2014/03/18 M1 M2 M3 M4 M5 M6 M7 Feature Complete M8 Developer Preview M9 Final Release Candidate GA General Availability
  • 3. Agenda Major changes 1 Why is Java still changing? 2 Lambda Project 3 Date and Time API 4 Type Annotations 5 Compact Profiles JUG
  • 4. Java 8 Is Revolutionary, Java Is Back “Lambda is the single largest upgrade to the programming model. Ever. It's larger even than Generics. It's the first time since the beginning of Java that we've done a carefully coordinated co-evolution of the virtual machine, the language and the libraries, all together. Yet the result still feels like Java. Mark Reinhold (Chief Architect of the Java Platform Group at Oracle)
  • 5. Java 8 Is Revolutionary, Java Is Back “Lambda is the single largest upgrade to the programming model. Ever. It's larger even than Generics. It's the first time since the beginning of Java that we've done a carefully coordinated co-evolution of the virtual machine, the language and the libraries, all together. Yet the result still feels like Java. Mark Reinhold (Chief Architect of the Java Platform Group at Oracle)
  • 7. Why is Java still changing?
  • 8. Why is Java still changing?
  • 9. Why is Java still changing?
  • 10. Why is Java still changing?
  • 11. Why is Java still changing?
  • 12. Why is Java still changing?
  • 13. Why is Java still changing?
  • 14. Why is Java still changing? The changing computing background big data multicore cloud computing Increasingly dealing with big data (terabytes and up) and wishing to exploit multicore computers or computing clusters effectively to process this. And this means using: parallel processing
  • 15. The Progress of Programming There`s been a lot of progress & Progress is being allowed to forget things!
  • 16. The Progress of Programming There`s been a lot of progress: - Assemblers let us forget opcodes
  • 17. The Progress of Programming There`s been a lot of progress: - Assemblers let us forget opcodes - Garbage collections let us forget memory management #include <stdio.h> #include <stdlib.h> int main () { … buffer = (char*) malloc (i+1); … free (buffer); … }
  • 18. The Progress of Programming So what about parallelism?
  • 19. Why Can`t We Forget About Parallelism? Most of parallelism problems are doing bulk operations on collection and we keep writing code like this: int sum = 0; for (int i = 0; i < a.length; i++) { sum += a[i]; } It is inherently serial
  • 20. Why Can`t We Forget About Parallelism? If the processing of different elements is to proceed in parallel, it is the responsibility of the client code
  • 21. Why Can`t We Forget About Parallelism? If the processing of different elements is to proceed in parallel, it is the responsibility of the client code n1 n2 n3 sum1 n4 n5 n6 n7 sum2 n8 n9 … … sum3 … … sum4
  • 22. Why Can`t We Forget About Parallelism? If the processing of different elements is to proceed in parallel, it is the responsibility of the client code n1 n2 n3 sum1 n4 n5 n6 n7 sum2 n8 n9 … … … … sum3 class Sum implements Callable<Long> { private final long from; private final long to; Sum(long from, long to) { this.from = from; this.to = to; } public Long call() { long acc = 0; for (long i = from; i <= to; i++) { acc = acc + i; } return acc; } } sum4
  • 23. Why Can`t We Forget About Parallelism? If the processing of different elements is to proceed in parallel, it is the responsibility of the client code n1 n2 n3 sum1 n4 n5 n6 n7 sum2 n8 n9 … … sum3 … … sum4 ExecutorService executor = Executors.newFixedThreadPool(2); List<Future<Long>> results = executor.invokeAll(asList( new Sum(1, 250), new Sum(251, 500), new Sum(551, 750), new Sum(751, 1000) )); for (Future<Long> result : results) { System.out.println(result.get()); }
  • 24. Why Can`t We Forget About Parallelism? Sequential Thread 1 Parallel (assuming a quad core machine) Thread 1 Thread 2 Thread 3 Thread 4 Time t Done parallel Done sequential
  • 25. Why Can`t We Forget About Parallelism? Let the Library Writers do it! Collection developers know the recursive structure of their data But right now they can`t use that knowledge
  • 26. Why Can`t We Forget About Parallelism? Let the Library Writers do it! Collection developers know the recursive structure of their data But right now they can`t use that knowledge int sum = 0; for (Iterator<Integer> itr = myList.iterator();itr.hasNext(); ) { sum += itr.next(); } The problem is external iteration
  • 27. Why Can`t We Forget About Parallelism? Internal Iteration Instead of this: int sum = 0; for (int i=0;i<myList.size();i++){ int a=myList.get(i); sum+=a; }
  • 28. Why Can`t We Forget About Parallelism? Internal Iteration Instead of this: We`re going to write this: int sum = 0; int [] sum = new int[1]; for (int i=0;i<myList.size();i++){ int a=myList.get(i); sum+=a; } myList.forEach( … );
  • 29. Why Can`t We Forget About Parallelism? Internal Iteration Instead of this: We`re going to write this: int sum = 0; int [] sum = new int[1]; for (int i=0;i<myList.size();i++){ int a=myList.get(i); sum+=a; } myList.forEach( … ); • Let the collection choose its iteration strategy - Parallel, serial, out-of-order, lazy, …
  • 30. Why Can`t We Forget About Parallelism? Internal Iteration Instead of this: We`re going to write this: int sum = 0; int [] sum = new int[1]; for (int i=0;i<myList.size();i++){ int a=myList.get(i); sum+=a; } myList.forEach( a -> sum[0]+=a ); • Let the collection choose its iteration strategy - Parallel, serial, out-of-order, lazy, …
  • 31. Why Can`t We Forget About Parallelism? a -> sum[0]+=a
  • 32. Lambda Project – JSR 335 JSR 335 (Lambda Project) aims to support programming in a multicore environment by adding closures and related features to the Java language.
  • 33. What are Lambda Expressions (closures)? A lambda expression :
  • 34. What are Lambda Expressions (closures)? A lambda expression : is an anonymous method
  • 35. What are Lambda Expressions (closures)? A lambda expression : is an anonymous method a -> having an argument list
  • 36. What are Lambda Expressions (closures)? A lambda expression : is an anonymous method a return type a -> having an argument list
  • 37. What are Lambda Expressions (closures)? A lambda expression : is an anonymous method a return type a -> having an argument list and a body sum[0]+=a
  • 38. What are Lambda Expressions (closures)? A lambda expression : is an anonymous method having an argument list a return type and a body and able to refer to values from the enclosing scope (closure) a -> sum[0]+=a
  • 39. What are Lambda Expressions (closures)? A lambda expression : is an anonymous method having an argument list To pass behavior to the API as data a return type and a body and able to refer to values from the enclosing scope (closure) a -> sum[0]+=a
  • 40. From Single Method Interface …. public interface Comparator<T> { }
  • 41. From Single Method Interface …. public interface Comparator<T> { int compare(T o1, T o2); }
  • 42. From Single Method Interface …. public interface Comparator<T> { int compare(T o1, T o2); Single Abstract Method (SAM) }
  • 43. From Single Method Interface …. public interface Comparator<T> { int compare(T o1, T o2); Single Abstract Method (SAM) } Functional Interface
  • 44. From Single Method Interface …. public interface Comparator<T> { int compare(T o1, T o2); } Collections.sort(strings, new Comparator<String>() { public int compare(String s1, String s2) { return s1.compareToIgnoreCase(s2); } });
  • 45. From Single Method Interface …. public interface Comparator<T> { int compare(T o1, T o2); } Collections.sort(strings, new Comparator<String>() { public int compare(String s1, String s2) { return s1.compareToIgnoreCase(s2); } });
  • 46. From Single Method Interface …. public interface Comparator<T> { int compare(T o1, T o2); } Collections.sort(strings, new Comparator<String>() { public int compare(String s1, String s2) { return s1.compareToIgnoreCase(s2); } });  Bulky syntax  Confusion surrounding the meaning of names and this
  • 47. … To Lambda Expressions Collections.sort(strings, (s1, s2) -> s1.compareToIgnoreCase(s2));
  • 48. … To Lambda Expressions Collections.sort(strings, (s1, s2) -> s1.compareToIgnoreCase(s2));
  • 49. … To Lambda Expressions Collections.sort(strings, (s1, s2) -> s1.compareToIgnoreCase(s2)); Lambda expression are always converted to instance of a functional interface Comparator<String> c = (s1, s2) -> s1.compareToIgnoreCase(s2)); No need of changing the JVM to create a new type for lambda expressions
  • 50. … To Lambda Expressions Collections.sort(strings, new Comparator<String>() { public int compare(String s1, String s2) { return s1.compareToIgnoreCase(s2); } }); Collections.sort(strings, (s1, s2) -> s1.compareToIgnoreCase(s2) );
  • 51. … To Lambda Expressions Collections.sort(strings, new Comparator<String>() { public int compare(String s1, String s2) { return s1.compareToIgnoreCase(s2); } }); Collections.sort(strings, (s1, s2) -> s1.compareToIgnoreCase(s2) );
  • 52. Without more language support for parallel idioms, people will instinctively reach for serial idioms
  • 53. External Iteration Sum of squares long sum = 0L; for (long i = 0; i < N; i++) { sum += i * i; }
  • 54. Internal Iteration Sum of squares long sum = LongStream.range(0, N) .map(i -> i * i) .sum();
  • 55. Internal Iteration Going parallel long sum = LongStream.range(0, N) .parallel() .map(i -> i * i) .sum();
  • 56. Parallel Streams A behavioral parameter (lambda) may be invoked concurrently – This constraint gives us “wiggle room” to optimize
  • 57. Up the level of abstraction External iteration conflates what with how Internal iteration: more what; less how Client passes behavior to the API as data Library is free to use Multiple threads Out-oforder execution Laziness
  • 58. Lambdas in Java 8 Code as data (Simplicity) Bulk data operations Lambda Interface evolution Multi-core processing / parallel processing
  • 60. Date and Time API JSR 310
  • 61. New Date and Time API History of Java Date/Time APIs Java.util.Date, java.util.Calendar - Strong candidates for the all-time worst Java platform library design Joda Time - Quality date and time library JSR-310 - Builds on experience of Joda Time
  • 62. New Date and Time API Design Principles Immutable - Thread-safe, allows caching Fluent - easy to read, like a DSL LocalDate.of(2013,Month.JANUARY,09).withYear(2014);
  • 63. New Date and Time API Time for Humans Field-base, designed for humans - Year,month,day,hour,minute,second - LocalDate,LocalDateTime,ZonedDateTime,Period …
  • 64. New Date and Time API Los Angeles 16:20 London 12:50
  • 65. New Date and Time API void flightTime() { LocalDate date = LocalDate.of(2013, Month.SEPTEMBER, 14); LocalTime takeoff = LocalTime.of(12, 50); LocalTime landing = LocalTime.of(16, 20); ZoneId LHR = ZoneId.of("Europe/London"); ZoneId SFO = ZoneId.of("America/Los_Angeles"); Duration flightTime = Duration.between( ZonedDateTime.of(date, takeoff, LHR), ZonedDateTime.of(date, landing, SFO)); System.out.println("Flight time: " + flightTime); }
  • 67. Type Annotations  JSR-308 brings annotations on Type use  Are an enabler for the checkers framework Ex.: new @Interned MyObject(); myString = (@NonNull String) myObject; void monitorTemperature() throws @Critical TemperatureException { ... }
  • 68. Repeating Annotations  Before @Schedules ({ @Schedule(dayOfMonth="Last"), @Schedule(dayOfWeek="Fri", hour="23") )} public void doPeriodicCleanup() { ... }
  • 69. Repeating Annotations  Before @Schedules ({ @Schedule(dayOfMonth="Last"), @Schedule(dayOfWeek="Fri", hour="23") )} public void doPeriodicCleanup() { ... }  After @Schedule(dayOfMonth="Last”) @Schedule(dayOfWeek="Fri", hour="23") public void doPeriodicCleanup() { ... }
  • 70. Java SE 8 Compact Profiles
  • 71. Java SE 8 Compact Profiles SE 8 Compact Profiles 3 SE Full JRE Optional Components UI & Toolkits 2 Compact3 Class libraries Integration Libraries Compact2 Class libraries Other Base Libraries Base Compact1 Classes Lang & Util Base Libraries Hotspot VM Hotspot VM 1
  • 72. Q&A
  • 73. References • Lambda http://stackoverflow.com/questions/220658/what-is-the-difference-between-a-closure-and-a-lambda http://openjdk.java.net/projects/lambda/ http://jcp.org/aboutJava/communityprocess/edr/jsr335/index2.html http://vimeo.com/48577033 (slides: http://www.slideshare.net/tkowalcz/java-gets-a-closure) http://datumedge.blogspot.co.uk/2012/06/java-8-lambdas.html http://www.theserverside.com/news/thread.tss?thread_id=68718 http://medianetwork.oracle.com/video/player/1785479333001 https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=6080 https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=5089 http://www.lektorium.tv/lecture/?id=14048 http://www.lektorium.tv/lecture/?id=14049 http://blog.xebia.com/2012/11/05/report-will-java-8s-lambda-change-the-face-of-the-world/ http://www.slideshare.net/fsarradin/java-8-lambda http://programmers.stackexchange.com/questions/173441/what-triggered-the-popularity-of-lambda-functions-in-modernmainstream-programmi?newsletter=1&nlcode=29983% 7c903a http://www.slideshare.net/bje/java-closures * Collections http://www.javabeat.net/2012/05/enhanced-collections-api-in-java-8-supports-lambda-expressions/ http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html http://architects.dzone.com/articles/java-collections-api
  • 74. References • Remove the Permanent Generation http://www.cubrid.org/blog/dev-platform/understanding-jvm-internals/ http://javaeesupportpatterns.blogspot.com/2011/10/java-7-features-permgen-removal.html http://java.dzone.com/articles/busting-permgen-myths https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=5135 • JSR 310: Date and Time API http://java.dzone.com/articles/introducing-new-date-and-time http://sourceforge.net/apps/mediawiki/threeten/index.php?title=ThreeTen http://www.infoq.com/news/2010/03/jsr-310 https://docs.google.com/document/pub?id=1rd8yplQZIRz3LxMzpVLuskr1b0HwBmK9PXpdgBYojSw http://sourceforge.net/apps/mediawiki/threeten/index.php?title=User_Guide https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=4350 • General Java8 http://openjdk.java.net/projects/jdk8/features http://www.pcadvisor.co.uk/news/software/3401314/oracle-java-upgrades-still-worthwhile-despite-postponed-features/ http://dhruba.name/2011/07/06/oracle-discusses-java-7-8-new-features-on-video/ http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012/Java-8 http://www.parleys.com/#st=5&id=2850&sl=1 http://www.parleys.com/#st=5&id=2847 https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=2872 https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=10458