Book description
The introduction of functional programming concepts in Java SE 8 was a drastic change for this venerable object-oriented language. Lambda expressions, method references, and streams fundamentally changed the idioms of the language, and many developers have been trying to catch up ever since. This cookbook will help. With more than 70 detailed recipes, author Ken Kousen shows you how to use the newest features of Java to solve a wide range of problems.
For developers comfortable with previous Java versions, this guide covers nearly all of Java SE 8, and includes a chapter focused on changes coming in Java 9. Need to understand how functional idioms will change the way you write code? This cookbook—chock full of use cases—is for you.
Recipes cover:
- The basics of lambda expressions and method references
- Interfaces in the java.util.function package
- Stream operations for transforming and filtering data
- Comparators and Collectors for sorting and converting streaming data
- Combining lambdas, method references, and streams
- Creating instances and extract values from Java’s Optional type
- New I/O capabilities that support functional streams
- The Date-Time API that replaces the legacy Date and Calendar classes
- Mechanisms for experimenting with concurrency and parallelism
Publisher resources
Table of contents
- Foreword
- Preface
- The Basics
- The java.util.function Package
-
Streams
- 3.1. Creating Streams
- 3.2. Boxed Streams
- 3.3. Reduction Operations Using Reduce
- 3.4. Check Sorting Using Reduce
- 3.5. Debugging Streams with peek
- 3.6. Converting Strings to Streams and Back
- 3.7. Counting Elements
- 3.8. Summary Statistics
- 3.9. Finding the First Element in a Stream
- 3.10. Using anyMatch, allMatch, and noneMatch
- 3.11. Stream flatMap Versus map
- 3.12. Concatenating Streams
- 3.13. Lazy Streams
-
Comparators and Collectors
- 4.1. Sorting Using a Comparator
- 4.2. Converting a Stream into a Collection
- 4.3. Adding a Linear Collection to a Map
- 4.4. Sorting Maps
- 4.5. Partitioning and Grouping
- 4.6. Downstream Collectors
- 4.7. Finding Max and Min Values
- 4.8. Creating Immutable Collections
- 4.9. Implementing the Collector Interface
-
Issues with Streams, Lambdas, and Method References
- 5.1. The java.util.Objects Class
- 5.2. Lambdas and Effectively Final
- 5.3. Streams of Random Numbers
- 5.4. Default Methods in Map
- 5.5. Default Method Conflict
- 5.6. Iterating Over Collections and Maps
- 5.7. Logging with a Supplier
- 5.8. Closure Composition
- 5.9. Using an Extracted Method for Exception Handling
- 5.10. Checked Exceptions and Lambdas
- 5.11. Using a Generic Exception Wrapper
- The Optional Type
- File I/O
-
The java.time Package
- 8.1. Using the Basic Date-Time Classes
- 8.2. Creating Dates and Times from Existing Instances
- 8.3. Adjusters and Queries
- 8.4. Convert from java.util.Date to java.time.LocalDate
- 8.5. Parsing and Formatting
- 8.6. Finding Time Zones with Unusual Offsets
- 8.7. Finding Region Names from Offsets
- 8.8. Time Between Events
- Parallelism and Concurrency
- Java 9 Additions
- Generics and Java 8
- Index
Product information
- Title: Modern Java Recipes
- Author(s):
- Release date: August 2017
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491973172
You might also like
video
Modern Java in Action video edition
"A comprehensive and practical introduction to the modern features of the latest Java releases with excellent …
book
Modern Java in Action
Manning's bestselling Java 8 book has been revised for Java 9 and 10! In Modern Java …
book
Functional Programming in Java
Functional Programming in Java teaches Java developers how to incorporate the most powerful benefits of functional …
book
Functional Programming in Java
Get ready to program in a whole new way. Functional Programming in Java will help you …