Your SlideShare is downloading. ×
0
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
Java 8 Lambda Expressions
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 Lambda Expressions

5,130

Published on

Slides for a lightning talk on Java 8 lambda expressions I gave at the Near Infinity (www.nearinfinity.com) 2013 spring conference. …

Slides for a lightning talk on Java 8 lambda expressions I gave at the Near Infinity (www.nearinfinity.com) 2013 spring conference.

The associated sample code is on GitHub at https://github.com/sleberknight/java8-lambda-samples

Published in: Technology, News & Politics
2 Comments
11 Likes
Statistics
Notes
No Downloads
Views
Total Views
5,130
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
209
Comments
2
Likes
11
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. ScottLeberknightJava 8λ Expressions
  • 2. Mom, why?Promote immutabilityDeclare what to do, not how to do itEasier parallelization & lazy evaluationCleaner, more concise code
  • 3. List<Integer> numbers =Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);numbers.forEach(new Consumer<Integer>() {@Overridepublic void accept(Integer integer) {System.out.println(integer);}});iterating w/ forEach(under the hood)
  • 4. lambda expressions(argument list) -> code(final String name, final int age) -> code(name, age) -> codename -> codeexamples:type inference(String name, int age) -> code}λ
  • 5. iterating w/lambdasList<Integer> numbers =Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);numbers.forEach((final Integer value) -> System.out.println(value));lambda expression
  • 6. iterating w/lambdas, type inferenceList<Integer> numbers =Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);numbers.forEach(value -> System.out.println(value));
  • 7. method referencesList<Integer> numbers =Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);numbers.forEach(System.out::println);method reference
  • 8. transforms using mapList<Integer> numbers =Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);numbers.stream().map(value -> value * 2).forEach(System.out::println);
  • 9. filteringList<Integer> numbers =Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);numbers.stream().filter(value -> value % 2 == 0).forEach(System.out::println);
  • 10. filtering v2List<String> names = Arrays.asList("Bob", "Tom", "Jeff", "Scott", "Jennifer", "Steve");final Function<String, Predicate<String>> startsWithLetter =letter -> name -> name.startsWith(letter);names.stream().filter(startsWithLetter.apply("J")).forEach(System.out::println);
  • 11. Streams.iterate(1, number -> number + 1).map(number -> number * number).limit(25).forEach(number -> System.out.print(number + " "));// 1 4 9 16 25 36 49 64 ... 529 576 625Streams
  • 12. finding with OptionalList<String> names = Arrays.asList("Bob", "Tom", "Jeff", "Scott", "Jennifer", "Steve");Optional<String> firstS = names.stream().filter(name -> name.startsWith("S")).findFirst();System.out.println(firstS.orElse("None found"));
  • 13. reducersList<String> names = Arrays.asList("Bob", "Tom", "Jeff", "Scott", "Jennifer", "Steve");Optional<String> longestName = names.stream().reduce((name1, name2) ->name1.length() >= name2.length() ? name1 : name2);if (longestName.isPresent()) {System.out.println(longestName.get());}
  • 14. sum reducerList<Integer> numbers =Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);long sum = numbers.stream().map(value -> value * value).sum();
  • 15. parallelizationnumbers.parallelStream().filter(number -> isPerfect(number)).forEach(System.out::println);
  • 16. how far we went in this short talk...
  • 17. http://pragprog.com/book/vsjava8/functional-programming-in-java
  • 18. http://jdk8.java.net/JDK 8 Project
  • 19. sample code available at:https://github.com/sleberknight/java8-lambda-samples
  • 20. My Infoscott dot leberknight at nearinfinity dot comtwitter.com/sleberknight www.sleberknight.com/blogwww.nearinfinity.com/blogs/scott_leberknight/all/scott dot leberknight at gmail dot com

×