Your SlideShare is downloading. ×
Java 8 - Under the Hood
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

Java 8 - Under the Hood

1,225
views

Published on

Presentation about upcoming features of Java 8 mainly with regard to functional programming (lambdas). The presentation compares the features with Scala. It was presented by Vlastimil Menčík at the …

Presentation about upcoming features of Java 8 mainly with regard to functional programming (lambdas). The presentation compares the features with Scala. It was presented by Vlastimil Menčík at the May's Czech Scala Enthusiasts meetup held at Faculty of Information Technology in Prague.

Published in: Technology, Education

0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,225
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
36
Comments
0
Likes
6
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. Java 8: Under the HoodVlastimil Menčík
  • 2. λ - syntaxx => x + 1_ + 1Integer.parseInt Integer::parseIntx -> x + 1MyClass MyClass::newif MyClass is a case class
  • 3. λ - types• functional interfacesaka SAM interfaces• target typing• applicable to legacyinterfaces• FunctionN• String => Int• Currying• PartialFunction
  • 4. Functional Interface
  • 5. Interoperability with Scala
  • 6. λ - implementation in Scala• instances of FunctionX traits• compiled into anonymous inner classesMyClass$$anonfun$1.class• a lot of extra bytecode
  • 7. λ - implementation in Java 8• implementation in synthetic methods• invokedynamic• LambdaMetafactory
  • 8. λ in bytecode
  • 9. invokedynamic• since Java 7• java.lang.invoke• what really gets invoked is resolved at runtimeby delegating to a bootstrap method
  • 10. LambdaMetafactory• contains bootstrap methods for converting λ-expressions to functional interface objects
  • 11. invokedynamic + LambdaMetafactoryinvokedynamic #2
  • 12. x -> x + 5
  • 13. When will this be in Scala?• after Scala moves away from Java 6• 2.11 will have experimental Java 7 backend• 2.12 will target Java 8
  • 14. Java 8: Stream API
  • 15. Parallel streams• very similar to parallel collections in Scalastream.parallel()stream.sequential()col.parcol.seq
  • 16. More lambdas in Java API• java.util.function– “standard” functional interfaces– Function, BiFunction, Predicate, Supplier, …• java.util.Optional<T>public T orElseGet(Supplier<? extends T> other)
  • 17. Default methodspublic interface Iterable<T> {default void forEach(…)}• necessary for backwards compatibility• useful in many other cases
  • 18. Does Java now have traits?• sort of, but not really – no state, no self types, no linearization (possiblediamond inheritance issues), …• default methods are means of painless APIevolution• traits are means of modularization
  • 19. Future benefits for Scala?• better bytecode representation for method-only traits• implemented methods no longer copied tosubtypes• could help with binary compatibility problems
  • 20. java.time• (finally) an immutable date representation• inspired by Joda Time
  • 21. Changes in JVM• PermGen replaced with Metaspace• hopefully future optimizations for functionalprogramming style
  • 22. And the release date?• umm…• when it’s done• hopefully next spring
  • 23. Where to go next?• https://jdk8.java.net/lambda/• http://www.lambdafaq.org/• http://lambdadoc.net/api/• http://youtu.be/-7OB2PxB_zg– my more Java-focused talk (in Czech)
  • 24. Q&A