SlideShare a Scribd company logo
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
What's new in Java 8
What's new in Java 8
What's new in Java 8
What's new in Java 8
• 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();
What's new in Java 8
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

PPTX
Java 8 Lambda and Streams
PPTX
Java 8 lambda
ODP
10 Things I Hate About Scala
PDF
Java8 features
PDF
Programming with Lambda Expressions in Java
PDF
Lambda Expressions in Java
PPTX
Lambda Expressions in Java 8
PDF
Java 8 Lambda Expressions & Streams
Java 8 Lambda and Streams
Java 8 lambda
10 Things I Hate About Scala
Java8 features
Programming with Lambda Expressions in Java
Lambda Expressions in Java
Lambda Expressions in Java 8
Java 8 Lambda Expressions & Streams

What's hot (20)

PPTX
java 8 new features
PDF
Java 8 - Project Lambda
PDF
PPTX
Programming picaresque
PPTX
Java 8 presentation
PPTX
Java 8 Feature Preview
PDF
Scala Code Analysis at Codacy
PDF
Java 8 ​and ​Best Practices
PPTX
10 Sets of Best Practices for Java 8
PPTX
New Features of JAVA SE8
ODP
Introduction to Java 8
PDF
Java 8 features
PPTX
Java 8 streams
PDF
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
PPTX
Lambdas and Laughs
PDF
Productive Programming in Java 8 - with Lambdas and Streams
PDF
Lambdas HOL
PPTX
Java 8 new features
PPTX
From Ruby to Scala
PDF
camel-scala.pdf
java 8 new features
Java 8 - Project Lambda
Programming picaresque
Java 8 presentation
Java 8 Feature Preview
Scala Code Analysis at Codacy
Java 8 ​and ​Best Practices
10 Sets of Best Practices for Java 8
New Features of JAVA SE8
Introduction to Java 8
Java 8 features
Java 8 streams
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
Lambdas and Laughs
Productive Programming in Java 8 - with Lambdas and Streams
Lambdas HOL
Java 8 new features
From Ruby to Scala
camel-scala.pdf
Ad

Viewers also liked (6)

PPT
whats new in java 8
PDF
Functional Programming in Java 8 - Exploiting Lambdas
PPTX
Java Collections Framework Inroduction with Video Tutorial
PDF
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
DOC
Cogeneration in Sugar mills
PDF
Functional Thinking - Programming with Lambdas in Java 8
whats new in java 8
Functional Programming in Java 8 - Exploiting Lambdas
Java Collections Framework Inroduction with Video Tutorial
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Cogeneration in Sugar mills
Functional Thinking - Programming with Lambdas in Java 8
Ad

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

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

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
System and Network Administration Chapter 2
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Introduction to Artificial Intelligence
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
AI in Product Development-omnex systems
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Which alternative to Crystal Reports is best for small or large businesses.pdf
System and Network Administration Chapter 2
Reimagine Home Health with the Power of Agentic AI​
How to Choose the Right IT Partner for Your Business in Malaysia
wealthsignaloriginal-com-DS-text-... (1).pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Introduction to Artificial Intelligence
Design an Analysis of Algorithms II-SECS-1021-03
Adobe Illustrator 28.6 Crack My Vision of Vector Design
VVF-Customer-Presentation2025-Ver1.9.pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
top salesforce developer skills in 2025.pdf
AI in Product Development-omnex systems
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Migrate SBCGlobal Email to Yahoo Easily
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...

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
  • 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();
  • 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

  • #5: Release themes
  • #6: Developer productivity Tools to generate code, languages to reduce ceremony, frameworks to remove boilerplate Images taken from their respective project sites.
  • #7: 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
  • #8: 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
  • #9: Alternate now: the cloud. Oh yeah, and distributed. Image source: http://www.google.com/about/datacenters/gallery/#/tech/20
  • #11: CHM pre-v8: 1.6 kb memory (empty) vs 100 bytes (Hashtable) v8 much closer now
  • #12: Adders
  • #13: AtomicLong - CAS, spin lock under high contention
  • #14: 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
  • #15: Works significantly better under contention than AtomicLong Image source: http://blog.palominolabs.com/2014/02/10/java-8-performance-improvements-longadder-vs-atomiclong/
  • #16: StampedLock
  • #17: Java 5: ReentrantRWL favors readers Java 6: RRWL favors writers
  • #18: Example from the StampedLock Javadoc StampedLock is not re-entrant, but performs better than RRWL
  • #19: Example from the StampedLock Javadoc
  • #20: The stamp from tryOptimisticRead is only good for validation, not unlocking as read/write lock stamps are
  • #21: CompletableFuture
  • #22: 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
  • #23: Switch to Javadoc if time Example from http://www.nurkiewicz.com/2013/05/java-8-definitive-guide-to.html
  • #24: Method references
  • #25: Static, non-static, even constructors
  • #26: Example from http://winterbe.com/posts/2014/03/16/java-8-tutorial/
  • #27: Default methods
  • #28: 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
  • #30: Functional interfaces
  • #31: Show Javadoc for java.util.function
  • #32: Lambda expressions
  • #33: 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
  • #36: Streams
  • #37: Java 1.4
  • #38: Java 5 w/new for loop
  • #39: Java 7
  • #40: Java 8
  • #42: 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’
  • #43: Show Javadoc page for Stream
  • #44: Example from B. Winterberg: http://winterbe.com/posts/2014/03/16/java-8-tutorial/
  • #45: sequential sort took: 794 ms
  • #46: parallel sort took: 277 ms
  • #47: sequential sort took: 794 ms