Functional Programming in Java

Book description

Get ready to program in a whole new way. Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that's also a breeze to parallelize. You'll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You'll design and write applications better using the new standards in Java 8 and the JDK.

Publisher resources

View/Submit Errata

Table of contents

  1. Functional Programming in Java
    1. Copyright
    2. For the Best Reading Experience...
    3. Table of Contents
    4. Foreword
    5. Praise for Functional Programming in Java
    6. Acknowledgments
    7. Preface
      1. Who’s This Book For
      2. What’s in This Book
      3. Java Version Used in This Book
      4. How to Read the Code Examples
      5. Online Resources
    8. Chapter 1: Hello, Lambda Expressions!
      1. Change the Way You Think
      2. The Big Gains of Functional-Style Code
      3. Why Code in the Functional Style?
      4. Evolution, Not Revolution
      5. A Little Sugar to Sweeten
      6. Recap
    9. Chapter 2: Using Collections
      1. Iterating through a List
      2. Transforming a List
      3. Finding Elements
      4. Reusing Lambda Expressions
      5. Using Lexical Scoping and Closures
      6. Picking an Element
      7. Reducing a Collection to a Single Value
      8. Joining Elements
      9. Recap
    10. Chapter 3: Strings, Comparators, and Filters
      1. Iterating a String
      2. Implementing the Comparator Interface
      3. Multiple and Fluent Comparisons
      4. Using the collect Method and the Collectors Class
      5. Listing All Files in a Directory
      6. Listing Select Files in a Directory
      7. Listing Immediate Subdirectories Using flatMap
      8. Watching a File Change
      9. Recap
    11. Chapter 4: Designing with Lambda Expressions
      1. Separating Concerns Using Lambda Expressions
      2. Delegating Using Lambda Expressions
      3. Decorating Using Lambda Expressions
      4. A Peek into the default Methods
      5. Creating Fluent Interfaces Using Lambda Expressions
      6. Dealing with Exceptions
      7. Recap
    12. Chapter 5: Working with Resources
      1. Cleaning Up Resources
      2. Using Lambda Expressions to Clean Up Resources
      3. Managing Locks
      4. Creating Concise Exception Tests
      5. Recap
    13. Chapter 6: Being Lazy
      1. Delayed Initialization
      2. Lazy Evaluations
      3. Leveraging the Laziness of Streams
      4. Creating Infinite, Lazy Collections
      5. Recap
    14. Chapter 7: Optimizing Recursions
      1. Using Tail-Call Optimization
      2. Speeding Up with Memoization
      3. Recap
    15. Chapter 8: Composing with Lambda Expressions
      1. Using Function Composition
      2. Using MapReduce
      3. Taking a Leap to Parallelize
      4. Recap
    16. Chapter 9: Bringing It All Together
      1. Essential Practices to Succeed with the Functional Style
      2. Performance Concerns
      3. Adopting the Functional Style
    17. Appendix 1: Starter Set of Functional Interfaces
      1. Consumer < T >
      2. Supplier < T >
      3. Predicate < T >
      4. Function < T, R >
    18. Appendix 2: Syntax Overview
      1. Defining a Functional Interface
      2. Creating No-Parameter Lambda Expressions
      3. Creating a Single-Parameter Lambda Expression
      4. Inferring a Lambda Expression’s Parameter Type
      5. Dropping Parentheses for a Single-Parameter Inferred Type
      6. Creating a Multi-Parameter Lambda Expression
      7. Calling a Method with Mixed Parameters
      8. Storing a Lambda Expression
      9. Creating a Multiline Lambda Expression
      10. Returning a Lambda Expression
      11. Returning a Lambda Expression from a Lambda Expression
      12. Lexical Scoping in Closures
      13. Passing a Method Reference of an Instance Method
      14. Passing a Method Reference to a static Method
      15. Passing a Method Reference to a Method on Another Instance
      16. Passing a Reference of a Method That Takes Parameters
      17. Using a Constructor Reference
      18. Function Composition
    19. Appendix 3: Web Resources
    20. Bibliography
      1. You May Be Interested In…

Product information

  • Title: Functional Programming in Java
  • Author(s):
  • Release date: February 2014
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781937785468