Java 8 new features
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Java 8 new features

on

  • 610 views

Java 8 presentation for FinJUG. Covers new features like lambda, default methods and new date time.

Java 8 presentation for FinJUG. Covers new features like lambda, default methods and new date time.

Statistics

Views

Total Views
610
Views on SlideShare
606
Embed Views
4

Actions

Likes
0
Downloads
32
Comments
0

2 Embeds 4

https://www.linkedin.com 3
http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Virtual extension methods / defender methods /default methods
  • There can be many default methods and they can be overriden
  • Result type is never defined. It is always inferred from context. Target typing!
  • Runnable is one of the SAM
  • Yes, there can be default methods.
  • First example fails – attempt to capture mutable variable. 0 = identity. Initial value and result if nothing

Java 8 new features Presentation Transcript

  • 1. JAVA 8 18.3.2014 FinJUG - Petteri Hietavirta @FinJUG @pethie
  • 2. History • Timeline of Java – JDK 1.0 1996 – JDK 1.1 1997 – J2SE 1.2 1998 – J2SE 1.3 2000 – J2SE 1.4 2002 – J2SE 5.0 2004 – Java SE 6 2006 – Java SE 7 2011 – Java SE 8 2014 – General Availibility today!
  • 3. Why such a long wait • Security improvements
  • 4. New features • Lambda Expressions &Virtual Extension Methods • Autoconf-Based Build System • Lambda-Form Representation for Method Handles • Compact Profiles • Prepare for Modularization • Leverage CPU Instructions for AES Cryptography • Nashorn JavaScript Engine • Mechanical Checking of Caller-Sensitive Methods • Document JDK API Support and Stability • Reduce Cache Contention on Specified Fields
  • 5. Gc / runtime • Remove the Permanent Generation • Retire Some Rarely-Used GC Combinations • EnhancedVerification Errors • Reduce Class Metadata Footprint • SmallVM • Fence Intrinsics
  • 6. core / lang • Launch JavaFX Applications • GeneralizedTarget-Type Inference • Annotations on JavaTypes • DocTree API • Add Javadoc to javax.tools • Remove the Annotation-ProcessingTool (apt) • Access to Parameter Names at Runtime • RepeatingAnnotations • Enhance javac to Improve Build Speed • DocLint
  • 7. libs • Parallel Array Sorting • Bulk Data Operations for Collections • Enhance Core Libraries with Lambda • Charset Implementation Improvements • javax.lang.model Implementation Backed by Core Reflection • Base64 Encoding & Decoding • Reduce Core-Library Memory Usage • Date &Time API • Concurrency Updates • JDBC 4.2 • Optimize java.text.DecimalFormat.format • Statically-Linked JNI Libraries • Handle Frequent HashMap Collisions with BalancedTrees
  • 8. i18n • Improve Locale Data Packaging and Adopt UnicodeCLDR Data • BCP 47 Locale Matching • Unicode 6.2
  • 9. security • HTTP URL Permissions • MS-SFU Kerberos 5 Extensions • TLS Server Name Indication (SNI) Extension • AEAD CipherSuites • Stronger Algorithms for Password-Based Encryption • Configurable Secure Random-NumberGeneration • Enhance the Certificate Revocation-Checking API • NSA Suite B Cryptographic Algorithms • SHA-224 Message Digests • PKCS#11 Crypto Provider for 64-bitWindows • Limited doPrivileged • Overhaul JKS-JCEKS-PKCS12 Keystores • JAXP 1.5: Restrict Fetching of External Resources
  • 10. Highlights • Default methods • Lambda, StreamAPI • DateTime
  • 11. Default methods public interface Demo { public void foo(); } class DemoImpl implements Demo { public void foo() { … } }
  • 12. public interface Demo { public void foo(); public void bar(); } class DemoImpl implements Demo { public void foo() { … } public void bar() { …. } }
  • 13. public interface Demo { public void foo(); default public void bar() { … } } class DemoImpl implements Demo { public void foo() { … } }
  • 14. λ Lambda • Lambda expressions are computational units that operate on some data (input) and produce some data (output) • Cleaner code, better suited for parallel and concurrent programming
  • 15. Syntax Argument list Arrow token Body (int x, int y) -> x+y (int x, int y) -> x + y () -> 42 (String s) -> { System.out.println(s); } n -> System.out.println(n) System.out :: println // method reference
  • 16. Runnable new Thread(new Runnable() { @Override public void run({ System.out.println(”verbose"); } }).start(); new Thread( () -> System.out.println(”simple") ).start();
  • 17. • SingleAbstract Method / functional interface interface IntegerMath{ int operation(int a,int b); } Usage: IntegerMath addition = (a,b) -> a+b IntegerMath multi = (a,b) -> a*b; System.out.println("Add lambda :"+ addition.operation(10, 4)); System.out.println("Multiply lambda :"+ multi.operation(10, 4));
  • 18. Foreach List names = Arrays.asList("Java", "Joe", "Sam"); names.forEach(n -> System.out.println(n));
  • 19. java.util.functional public interface Predicate<T>{ boolean test(T t); } Predicate<String> startsWithJ = (n) -> n.startsWith("J");
  • 20. Stream API - filter names.stream() .filter(startsWithJ) .forEach((n) -> System.out.println(n))
  • 21. map names.stream() .map((name) -> name.toUpperCase()) .collect(Collectors.toList())
  • 22. reduce int sum = 0; list.forEach(e -> { sum += e.size(); }); int sum = Stream.of(1,2,3,4) .reduce(0,(a, b) -> a + b);
  • 23. parallel names.parallelStream() .filter(…
  • 24. Things to watch out • Non-final variable capture • Handling checked exceptions is pain • Control flow – no break, no early return • Nasty to debug in parallel context • Benchmark
  • 25. JSR-310 DateTime API • Build on experiences from Jodatime • java.time • Based on nanoseconds • Clear, fluent, immutable, extensible
  • 26. Immutable LocalDate dateOfBirth = LocalDate.of(2012, Month.MAY, 14); LocalDate firstBirthday = dateOfBirth.plusYears(1);
  • 27. Adjusters • PreviousThursday of any date date.with(TemporalAdjuster.previous (DayOfWeek.THURSDAY)));
  • 28. Payday Twice a month, 15th and the last day. If day is Sat or Sun, then happens on previous Fri LocalDate nextPayday = date.with(new PaydayAdjuster());
  • 29. public Temporal adjustInto(Temporal input) { LocalDate date = LocalDate.from(input); int day; if (date.getDayOfMonth() < 15) { day = 15; } else { day = date.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); } date = date.withDayOfMonth(day); if (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY) { date = date.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY)); } return input.with(date); }
  • 30. Period LocalDate today = LocalDate.now(); LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1); Period p = Period.between(birthday, today); long p2 = ChronoUnit.DAYS.between(birthday, today); System.out.println( "You are " + p.getYears() + " years, " + p.getMonths() + " months, and " + p.getDays() + " days old. (" + p2 + " days total)");
  • 31. Compact profiles 10Mb 17Mb 24Mb 140Mb
  • 32. Missing from Java 8 • Jigsaw • Java 9 coming – maybe 2016?
  • 33. IDE support • IntelliJ IDEA 12 & 13 • Eclipse Kepler (4.3) & Luna (4.4) • Netbeans 7.4+
  • 34. Oracle launch webcast Tuesday, 25 Mar 2014 https://blogs.oracle.com/java/entry/plans_for_j ava_8 http://eventreg.oracle.com/profile/web/index.cf m?PKWebId=0x637279c68
  • 35. Stream API presentations • http://www.jfokus.se/jfokus14/preso/Lambda s-Programming-Lab.pdf • http://www.jfokus.se/jfokus14/preso/Navigati ng-the-stream-API.pdf
  • 36. Thank you!