SlideShare a Scribd company logo
1 of 38
What’s new in Java 8
Kyle Smith
linkedin.com/in/kylesm
@kylesm
• Concurrency improvements
• Default methods
• Functional interfaces
• Lambda expressions
• Method references
• Streams
• Date/time
• Optional
• JavaScript
• JVM PermGen
• Base64 support
• Compact profiles
• Annotation improvements
• Type inference improvements
• Method parameter reflection
• JDBC 4.2
• Concurrency improvements
• Default methods
• Functional interfaces
• Lambda expressions
• Method references
• Streams
• Date/time
• Optional
• JavaScript
• JVM PermGen
• Base64 support
• Compact profiles
• Annotation improvements
• Type inference improvements
• Method parameter reflection
• JDBC 4.2
Themes
• ConcurrentHashMap — all new (inside)!
• LongAdder, DoubleAdder
• StampedLock
• CompletableFuture
Adders
• New classes for concurrent counters
• Waaaayyy more scalable than AtomicLong,etc.
• …if you can tolerate some inaccuracy
LongAdder clicks = new LongAdder();
clicks.increment();
// or counter.add(long)
// ...
clicks.sum();
StampedLock
• Alternative to ReentrantReadWriteLock
• “does not consistently prefer readers over writers or
vice versa"
• Provides optimistic reads
void move(double deltaX, double deltaY){
long stamp = sl.writeLock();
try {
x += deltaX;
y += deltaY;
} finally {
sl.unlockWrite(stamp);
}
}
double distanceFromOrigin() {
long stamp = sl.tryOptimisticRead();
double currentX = x, currentY = y;
if (!sl.validate(stamp)) {
stamp = sl.readLock();
try {
currentX = x;
currentY = y;
} finally {
sl.unlockRead(stamp);
}
}
return Math.sqrt(currentX * currentX
+ currentY * currentY);
}
CompletableFuture
• Everybody wants to be event-driven & reactive
• CompletableFuture allows composition of async
work
CompletableFuture<String> f1 = //…
CompletableFuture<Double> f2 = f1
.thenApply(Integer::parseInt)
.thenApply(r -> r * r * Math.PI);
Default methods
• Interfaces can supply non-abstract methods
• Enables existing interfaces to evolve
• Eliminates the need for companion (“garbage”)
classes
// java.lang.Iterable
default void forEach(Consumer<? super T>
action) {
Objects.requireNonNull(action);
for (T t : this) {
action.accept(t);
}
}
Functional interfaces
• Any interface with a single abstract method
• Examples:
• java.util.Comparator
• java.lang.Runnable
• Can be annotated with @FunctionalInterface
Lambda expressions
• Function values in Java
• Compatible with a functional interface when their
shapes match
• Syntax: (parameters) -> expression
DoubleUnaryOperator op1 =
(double r) -> r * r * Math.PI;
DoubleUnaryOperator op2 =
(r) -> r * r * Math.PI;
Runnable r =
() -> System.out.println("Hi, NEJUG!");
void cut(List<String> l, int len) {
l.replaceAll(s -> s.substring(0, len));
}
Streams
public Collection<Person>
findStudents(List<Person> people) {
Collection<Person> students =
new ArrayList<>();
for (Person p : people) {
if (p.isStudent()) {
students.add(p);
}
}
return students;
}
public Collection<Person>
findStudents(List<Person> people) {
Collection<Person> students =
new ArrayList<Person>();
people.forEach(i -> {
if (i.isStudent()) {
students.add(i);
}
});
return students;
}
public Collection<Person>
findStudents(List<Person> people) {
return people
.stream()
.filter(p -> p.isStudent())
.collect(Collectors.toList());
}
• “ A sequence of elements on which one or more
operations can be performed”
• Operations are either intermediate or terminal
• Streams can be sequential or parallel
• Intermediates:
• map, filter, flatMap, sorted, allMatch, anyMatch,
findAny, findFirst, flatMap, …
• Terminal:
• collect, count, forEach,reduce, max, min, …
long count = values
.stream()
.sorted()
.count();
long count = values
.parallelStream()
.sorted()
.count();
What next?
• Download JDK 8 from java.oracle.com
• IDE Support:
• Eclipse 4.3.2 SR2 (with patches!)
• IntelliJ IDEA 12.0+
• NetBeans IDE 8.0
Can’t move to Java 8?
• Google Guava (Java 6+)
• jsr166e (Java 6+)
• CHMv8, F/J tweaks, StampedLock, etc.
• Mix in some Groovy
• GPars
References:
http://bit.ly/1fRGyQV

More Related Content

What's hot

java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project LambdaRahman USTA
 
Programming picaresque
Programming picaresqueProgramming picaresque
Programming picaresqueBret McGuire
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentationVan Huong
 
Scala Code Analysis at Codacy
Scala Code Analysis at CodacyScala Code Analysis at Codacy
Scala Code Analysis at CodacyJohann Oikonomou
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8Garth Gilmour
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8Dinesh Pathak
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8Knoldus Inc.
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 

What's hot (20)

java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Java8
Java8Java8
Java8
 
Programming picaresque
Programming picaresqueProgramming picaresque
Programming picaresque
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Scala Code Analysis at Codacy
Scala Code Analysis at CodacyScala Code Analysis at Codacy
Scala Code Analysis at Codacy
 
Java 8 ​and ​Best Practices
Java 8 ​and ​Best PracticesJava 8 ​and ​Best Practices
Java 8 ​and ​Best Practices
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
Lambdas and Laughs
Lambdas and LaughsLambdas and Laughs
Lambdas and Laughs
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Lambdas HOL
Lambdas HOLLambdas HOL
Lambdas HOL
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 

Viewers also liked

whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8 Dori Waldman
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasGanesh Samarthyam
 
Java Collections Framework Inroduction with Video Tutorial
Java Collections Framework Inroduction with Video TutorialJava Collections Framework Inroduction with Video Tutorial
Java Collections Framework Inroduction with Video TutorialMarcus Biel
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
Cogeneration in Sugar mills
Cogeneration in Sugar millsCogeneration in Sugar mills
Cogeneration in Sugar millsPhani Mohan K
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Ganesh Samarthyam
 

Viewers also liked (6)

whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting Lambdas
 
Java Collections Framework Inroduction with Video Tutorial
Java Collections Framework Inroduction with Video TutorialJava Collections Framework Inroduction with Video Tutorial
Java Collections Framework Inroduction with Video Tutorial
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Cogeneration in Sugar mills
Cogeneration in Sugar millsCogeneration in Sugar mills
Cogeneration in Sugar mills
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8
 

Similar to What's new in Java 8

A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern JavaSina Madani
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New featuresSon Nguyen
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streamsjessitron
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New FeaturesNaveen Hegde
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Mario Camou Riveroll
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/HibernateSunghyouk Bae
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersNLJUG
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Sam Brannen
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Simon Ritter
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaMartijn Blankestijn
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Nayden Gochev
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?Chuk-Munn Lee
 

Similar to What's new in Java 8 (20)

Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern Java
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New features
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
Java8.part2
Java8.part2Java8.part2
Java8.part2
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen Borgers
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 Overview
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Java 8
Java 8Java 8
Java 8
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
 

Recently uploaded

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
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
 
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
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
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
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
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
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
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
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 

Recently uploaded (20)

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
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
 
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
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
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)
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
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...
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
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...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 

What's new in Java 8

  • 1. What’s new in Java 8 Kyle Smith linkedin.com/in/kylesm @kylesm
  • 2. • Concurrency improvements • Default methods • Functional interfaces • Lambda expressions • Method references • Streams • Date/time • Optional • JavaScript • JVM PermGen • Base64 support • Compact profiles • Annotation improvements • Type inference improvements • Method parameter reflection • JDBC 4.2
  • 3. • Concurrency improvements • Default methods • Functional interfaces • Lambda expressions • Method references • Streams • Date/time • Optional • JavaScript • JVM PermGen • Base64 support • Compact profiles • Annotation improvements • Type inference improvements • Method parameter reflection • JDBC 4.2
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. • ConcurrentHashMap — all new (inside)! • LongAdder, DoubleAdder • StampedLock • CompletableFuture
  • 11. • New classes for concurrent counters • Waaaayyy more scalable than AtomicLong,etc. • …if you can tolerate some inaccuracy
  • 12. LongAdder clicks = new LongAdder(); clicks.increment(); // or counter.add(long) // ... clicks.sum();
  • 13.
  • 15. • Alternative to ReentrantReadWriteLock • “does not consistently prefer readers over writers or vice versa" • Provides optimistic reads
  • 16. void move(double deltaX, double deltaY){ long stamp = sl.writeLock(); try { x += deltaX; y += deltaY; } finally { sl.unlockWrite(stamp); } }
  • 17. double distanceFromOrigin() { long stamp = sl.tryOptimisticRead(); double currentX = x, currentY = y; if (!sl.validate(stamp)) { stamp = sl.readLock(); try { currentX = x; currentY = y; } finally { sl.unlockRead(stamp); } } return Math.sqrt(currentX * currentX + currentY * currentY); }
  • 19. • Everybody wants to be event-driven & reactive • CompletableFuture allows composition of async work
  • 20. CompletableFuture<String> f1 = //… CompletableFuture<Double> f2 = f1 .thenApply(Integer::parseInt) .thenApply(r -> r * r * Math.PI);
  • 22. • Interfaces can supply non-abstract methods • Enables existing interfaces to evolve • Eliminates the need for companion (“garbage”) classes
  • 23. // java.lang.Iterable default void forEach(Consumer<? super T> action) { Objects.requireNonNull(action); for (T t : this) { action.accept(t); } }
  • 25. • Any interface with a single abstract method • Examples: • java.util.Comparator • java.lang.Runnable • Can be annotated with @FunctionalInterface
  • 27. • Function values in Java • Compatible with a functional interface when their shapes match • Syntax: (parameters) -> expression
  • 28. DoubleUnaryOperator op1 = (double r) -> r * r * Math.PI; DoubleUnaryOperator op2 = (r) -> r * r * Math.PI; Runnable r = () -> System.out.println("Hi, NEJUG!"); void cut(List<String> l, int len) { l.replaceAll(s -> s.substring(0, len)); }
  • 30. public Collection<Person> findStudents(List<Person> people) { Collection<Person> students = new ArrayList<>(); for (Person p : people) { if (p.isStudent()) { students.add(p); } } return students; }
  • 31. public Collection<Person> findStudents(List<Person> people) { Collection<Person> students = new ArrayList<Person>(); people.forEach(i -> { if (i.isStudent()) { students.add(i); } }); return students; }
  • 32. public Collection<Person> findStudents(List<Person> people) { return people .stream() .filter(p -> p.isStudent()) .collect(Collectors.toList()); }
  • 33. • “ A sequence of elements on which one or more operations can be performed” • Operations are either intermediate or terminal • Streams can be sequential or parallel
  • 34. • Intermediates: • map, filter, flatMap, sorted, allMatch, anyMatch, findAny, findFirst, flatMap, … • Terminal: • collect, count, forEach,reduce, max, min, …
  • 35. long count = values .stream() .sorted() .count(); long count = values .parallelStream() .sorted() .count();
  • 36. What next? • Download JDK 8 from java.oracle.com • IDE Support: • Eclipse 4.3.2 SR2 (with patches!) • IntelliJ IDEA 12.0+ • NetBeans IDE 8.0
  • 37. Can’t move to Java 8? • Google Guava (Java 6+) • jsr166e (Java 6+) • CHMv8, F/J tweaks, StampedLock, etc. • Mix in some Groovy • GPars

Editor's Notes

  1. Release themes
  2. Developer productivity Tools to generate code, languages to reduce ceremony, frameworks to remove boilerplate Images taken from their respective project sites.
  3. Improve application performance Then: 1-2 CPUs, synchronized keyword and direct use of threads Image source: http://en.wikipedia.org/wiki/File:Inside_and_Rear_of_Webserver.jpg
  4. Now: Dell PowerEdge M915: 64 cores per blade Today’s world: lock-free, non-blocking, little to no synchronization, immutability use of thread pools or higher-level abstractions Image source: http://en.community.dell.com/dell-blogs/direct2dell/b/direct2dell/archive/2011/11/29/a-little-clarity.aspx
  5. Alternate now: the cloud. Oh yeah, and distributed. Image source: http://www.google.com/about/datacenters/gallery/#/tech/20
  6. CHM pre-v8: 1.6 kb memory (empty) vs 100 bytes (Hashtable) v8 much closer now
  7. Adders
  8. AtomicLong - CAS, spin lock under high contention
  9. LA works by trying to have threads operate on different variables. Internally it’s a hash table of cells (akin to AtomicLongs) and hashing thread IDs means most threads will write to uncontended cells Number of cells grows as the contention grows
  10. Works significantly better under contention than AtomicLong Image source: http://blog.palominolabs.com/2014/02/10/java-8-performance-improvements-longadder-vs-atomiclong/
  11. StampedLock
  12. Java 5: ReentrantRWL favors readers Java 6: RRWL favors writers
  13. Example from the StampedLock Javadoc StampedLock is not re-entrant, but performs better than RRWL
  14. Example from the StampedLock Javadoc
  15. The stamp from tryOptimisticRead is only good for validation, not unlocking as read/write lock stamps are
  16. CompletableFuture
  17. Very useful for building event-driven/reactive systems, execution pipelines Overly complex to manage the flow w/callbacks Hard to write code that is easy to reason about CF makes it easy to build a workflow Kind of like promises in JavaScript
  18. Switch to Javadoc if time Example from http://www.nurkiewicz.com/2013/05/java-8-definitive-guide-to.html
  19. Method references
  20. Static, non-static, even constructors
  21. Example from http://winterbe.com/posts/2014/03/16/java-8-tutorial/
  22. Default methods
  23. Uses ‘default’ keyword Classes win over interfaces; if a class in the superclass chain supplies a declaration (concrete or abstract) the class wins every time; defaults won’t matter ⁃ More specific interfaces win (where “specificity” == sub-typing); default from List beats default from Collection ⁃ If there’s not a unique winner from #1 & #2 concrete class must disambiguate manually Object methods about state, interfaces don’t have state, classes do
  24. Functional interfaces
  25. Show Javadoc for java.util.function
  26. Lambda expressions
  27. Anonymous functions Act as closure (“capturing” or not) “Capturing” if it accesses non-static variables from outside lambda body Doesn’t define a new scope like inner classes Compatible with a FI when their shapes match Better libraries in Java
  28. Streams
  29. Java 1.4
  30. Java 5 w/new for loop
  31. Java 7
  32. Java 8
  33. Allows you get away from imperative programming and let the libraries decide Separates ‘what you want to do’ from ‘how you want to do it’
  34. Show Javadoc page for Stream
  35. Example from B. Winterberg: http://winterbe.com/posts/2014/03/16/java-8-tutorial/
  36. sequential sort took: 794 ms
  37. parallel sort took: 277 ms
  38. sequential sort took: 794 ms