Your SlideShare is downloading. ×
0
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Smart Migration to JDK 8
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Smart Migration to JDK 8

9,684

Published on

Key points of migrating to JDK 8 Language Features.

Key points of migrating to JDK 8 Language Features.

Published in: Technology, News & Politics
2 Comments
1 Like
Statistics
Notes
  • Great overview on JDK8 and its most relevant changes.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I know that going from secuential to parallel takes huge performance advantages when migration to java 8. But in the case of going from anonymous inner classes to lambdas, what advantages do you obtain apart from eliminating boilerplate code? does this change to lambdas has performance impact?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
9,684
On Slideshare
0
From Embeds
0
Number of Embeds
38
Actions
Shares
0
Downloads
46
Comments
2
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 1
  • 2. Smart Migration to JDK 8 2
  • 3. Language Changes in Java 8 Themes  From Imperative to Functional – Use modern constructs other newer languages use. – Enhance code readability. – Strip out the boilerplate code. – Stop telling the compiler what to do.  From Sequential to Parallel – Execute code in parallel without extra effort. – Divide problems into subproblems solve subproblems simultaneously and combine the results. – Aggregate operations instead of fork/join. 3
  • 4. Language Changes in Java 8 From Imperative to Functional, From Sequential to Parallel  Virtual extension methods  Functional interfaces  Lambdas  Method references  Streams  Collections  Time  Concurrency  IO/NIO  Reflections and annotations  Miscellaneous 4
  • 5. Building Blocks of Java 8 From Imperative to Functional, From Sequential to Parallel  Virtual extension methods – Break existing code when adding a method to an interface? – Java 8 allows to add new methods to interfaces. – Revolutionary – interface evolution is now possible.  Functional interfaces – A functional interface defines exactly one abstract method, focused on one specific task. – For example, java.lang.Runnable defines one abstract method “run()”. – @FunctionalInterface 5
  • 6. Lambda From Imperative to Functional, From Sequential to Parallel  Remove boilerplate code of anonymous inner classes. Better syntax. 6
  • 7. Demo How to Migrate to Lambdas 7
  • 8. Functions From Imperative to Functional, From Sequential to Parallel  java.util.Function – defines new functional interfaces, in addition to EventHandler, etc. 8
  • 9. Functions From Imperative to Functional, From Sequential to Parallel  java.util.Function – defines new functional interfaces, in addition to EventHandler, etc. New Functional Interfaces Function<T,R> BiFunction, ToIntFunction, LongToIntFunction, etc. Predicate<T> IntPredicate, LongPredicate, DoublePredicate, etc. Consumer<T> IntConsumer, DoubleConsumer, LongConsumer, etc. Supplier<T> IntSupplier, BinarySupplier, DoubleSupplier, etc. BinaryOperator<T> 9 Many Primitive Specializations IntBinaryOperator, IntUnaryOperator, etc.
  • 10. Streams: Pipes & Filters From Imperative to Functional, From Sequential to Parallel  java.util.Stream – provides a pipeline with filters. Source is processed through a pipe.  Each successive aggregate operation in the pipeline is one of: – Intermediate – map, filter, sorted, distinct, limit, skip, substream – Terminal – forEach, sum, collect, reduce, count, findFirst, findAny  Lazy evaluation – process only as needed and as many times as needed, e.g., “findFirst”.  No intermediate storage. 10
  • 11. Streams: Classes & Methods From Imperative to Functional, From Sequential to Parallel IntStream Builder LongStream DoubleStream anyMatch distinct concat noneMatch empty count range of parallel 11 map max peek allMatch forEachOrder findAny flatMap collect min findFirst sequential forEach limit iterate reduce skip sorted toArray filter builder boxed generate
  • 12. Streams: Collections From Imperative to Functional, From Sequential to Parallel  Distinguish between “what should be done” and “how it should be done”.  Collections APIs have been extended. Collections can be exposed as Streams.  Identify and refactor “for” loops. Replace with internal iterations provided by Streams.  That lets you express concurrent processing of elements in parallel. 12
  • 13. 13
  • 14. Demo How to Migrate to Streams 14
  • 15. Method Reference From Imperative to Functional, From Sequential to Parallel  Method references are an abbreviated style for expressing lambdas. x -> String.valueOf(x) x -> x.toString () -> x.toString() () -> new ArrayList() / / / / String::valueOf Object::toString x::toString ArrayList::new  Where a method already exists to perform an operation, a method reference can be used instead of a lambda. 15
  • 16. Demo How to Migrate to Method References 16
  • 17. Automation and Batch Processing From Imperative to Functional, From Sequential to Parallel  Refactoring tool scans across a scope – all projects, single project, single package, file...  Find candidates for upgrading to lambdas, functional operations, and method references. 17
  • 18. Demo Automation and Batch Processing 18
  • 19. Getting Started From Imperative to Functional, From Sequential to Parallel  Download NetBeans IDE 8.  Register JDK 8 in the IDE.  Set JDK 8 on the project.  Change Source Format to JDK 8. 19
  • 20. Demo Getting Started 20
  • 21. Community Feedback From Imperative to Functional, From Sequential to Parallel 21
  • 22. Summary From Imperative to Functional, From Sequential to Parallel  Virtual extension methods and functional interfaces make lambdas possible.  Lambdas remove boilerplate code of anonymous inner classes.  Streams provide pipelines, filters, and parallelism to Collections.  Method references are an alternative shorthand for lambdas. 22
  • 23. Next Steps 23
  • 24. References From Imperative to Functional, From Sequential to Parallel  http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html  http://blog.hartveld.com/2013/03/jdk-8-13-interface-default-method.html  http://www.techempower.com/blog/2013/03/26/everything-about-java-8/  http://technology.amis.nl/2013/10/05/java-8-collection-enhancements-leveraging-lambda-expressions-or-how-java- emulates-sql/  http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html  http://drunkendev.blogspot.nl/2014/01/migrating-to-jdk-8-with-netbeans.html  http://devoxx.com/display/DV12/Closures+and+Collections+-+the+World+After+Eight  http://refactoring.info/tools/LambdaFicator/ 24
  • 25. 25

×