Mastering Lambdas

Book description

The Definitive Guide to Lambda Expressions

Mastering Lambdas: Java Programming in a Multicore World describes how the lambda-related features of Java SE 8 will enable Java to meet the challenges of next-generation parallel hardware architectures. The book explains how to write lambdas, and how to use them in streams and in collection processing, providing code examples throughout. You'll learn how to use lambda expressions to take full advantage of performance improvements provided by today's multicore hardware. This Oracle Press book covers:

  • Why lambdas were needed, and how they will change Java programming
  • Syntax of lambda expressions
  • The basic operation of streams and pipelines
  • Using collectors and reduction to end pipelines
  • Creating streams
  • Spliterators, the fork/join framework, and exceptions
  • Examining stream performance with microbenchmarking
  • API evolution using default methods

Table of contents

  1. Cover
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. Contents
  6. Foreword
  7. Acknowledgments
  8. Introduction
  9. 1 Taking Java to the Next Level
    1. 1.1 From External to Internal Iteration
      1. 1.1.1 Internal Iteration
      2. 1.1.2 The Command Pattern
      3. 1.1.3 Lambda Expressions
    2. 1.2 From Collections to Streams
    3. 1.3 From Sequential to Parallel
    4. 1.4 Composing Behaviors
    5. 1.5 Conclusion
  10. 2 The Basics of Java Lambda Expressions
    1. 2.1 What Is a Lambda Expression?
      1. 2.1.1 The Syntax of Lambdas
    2. 2.2 Lambdas vs. Anonymous Inner Classes
      1. 2.2.1 No Identity Crisis
      2. 2.2.2 Scoping Rules for Lambdas
    3. 2.3 Variable Capture
    4. 2.4 Functional Interfaces
    5. 2.5 Using Lambda Expressions
    6. 2.6 Method and Constructor References
      1. 2.6.1 Static Method References
      2. 2.6.2 Instance Method References
      3. 2.6.3 Constructor References
    7. 2.7 Type Checking
      1. 2.7.1 What Exactly Is a Function Type?
      2. 2.7.2 Matching a Function Type
    8. 2.8 Overload Resolution
      1. 2.8.1 Overloading with Lambda Expressions
      2. 2.8.2 Overloading with Method References
    9. 2.9 Conclusion
  11. 3 Introduction to Streams and Pipelines
    1. 3.1 Stream Fundamentals
      1. 3.1.1 Parallel-Ready Code
      2. 3.1.2 Primitive Streams
    2. 3.2 Anatomy of a Pipeline
      1. 3.2.1 Starting Pipelines
      2. 3.2.2 Transforming Pipelines
      3. 3.2.3 Non-interference
      4. 3.2.4 Ending Pipelines
    3. 3.3 Conclusion
  12. 4 Ending Streams: Collection and Reduction
    1. 4.1 Using Collectors
      1. 4.1.1 Stand-alone Predefned Collectors
      2. 4.1.2 Composing Collectors
      3. 4.1.3 Chaining Pipelines
      4. 4.1.4 Worked Example: Most Popular Topics
    2. 4.2 Anatomy of a Collector
      1. 4.2.1 Concurrent Collection
    3. 4.3 Writing a Collector
      1. 4.3.1 Finishers
      2. 4.3.2 Worked Example: Finding My Books
      3. 4.3.3 Rules for Collectors
    4. 4.4 Reduction
      1. 4.4.1 Reduction over Primitives
      2. 4.4.2 Reduction over Reference Streams
      3. 4.4.3 Composing Collectors with Reduction
    5. 4.5 Conclusion
  13. 5 Starting Streams: Sources and Spliterators
    1. 5.1 Creating Streams
    2. 5.2 Spliterators and Fork/Join
      1. 5.2.1 Streams from Spliterators
    3. 5.3 Exceptions
    4. 5.4 Worked Example: Recursive grep
    5. 5.5 Conclusion
  14. 6 Stream Performance
    1. 6.1 Microbenchmarking
      1. 6.1.1 Measuring a Dynamic Runtime
      2. 6.1.2 The Java Microbenchmarking Harness
      3. 6.1.3 Experimental Method
    2. 6.2 Choosing Execution Mode
    3. 6.3 Stream Characteristics
    4. 6.4 Ordering
    5. 6.5 Stateful and Stateless Operations
    6. 6.6 Boxing and Unboxing
    7. 6.7 Spliterator Performance
    8. 6.8 Collector Performance
      1. 6.8.1 Concurrent Map Merge
      2. 6.8.2 Performance Analysis: Point Grouping
      3. 6.8.3 Performance Analysis: Finding My Books
    9. 6.9 Conclusion
  15. 7 API Evolution with Default Methods
    1. 7.1 Using Default Methods
    2. 7.2 What Role for Abstract Classes?
    3. 7.3 Default Method Syntax
    4. 7.4 Default Methods and Inheritance
      1. 7.4.1 Compatibility Problems
    5. 7.5 Static Methods in Interfaces
      1. 7.5.1 Using Static Methods
    6. 7.6 Conclusion
  16. Conclusion
  17. Index

Product information

  • Title: Mastering Lambdas
  • Author(s): Maurice Naftalin
  • Release date: October 2014
  • Publisher(s): McGraw Hill Computing
  • ISBN: 9780071829632