Book Review: All About Java 8 Lambdas
All About Java 8 Lambdas as a title doesn’t do the book justice. In fact, it contains a plethora of information about new features that have been added to Java 8, which includes lambdas, but also much, much more. The book is described as a “Weekend Read”, and at a little over 150 pages is certainly svelte enough to do so.
The book’s contents are split up into 14 chapters, with the first third covering lambdas. The middle third looks at predicates and the functional interface type and functional composition. The remaining third is dedicated to streams and stream processing, including parallel and sequential processes, using the lambdas and functions seen so far. Together, the chapters dovetail nicely together and also demonstrate some of Java 8’s other features, such as static and default methods on interfaces as well as method and constructor references.
The chapters themselves are well thought out and logical, interspersed as they are with examples and code snippets that back up the book’s GitHub repository. In fact, almost all pages have at least some code samples on them, and the surrounding text explains what that particular snippet does.
The reader is exposed to some types of new syntax right from the start; the introductory chapter explains the purpose of lambdas and demonstrates both in-line lambdas and method references. It then spends the next few chapters dissecting the examples with a more precise treatment of the syntax and the special cases that may apply.
The book’s coverage of functional programming starts off with an introduction to the purpose of functions and the
FunctionalInterface annotation. It then introduces more specific types such as
BiFunction, along with examples of each. Although the author could have stopped here, he kept going and showed how to chain functional results together and use them to build up chains of processing.
The book them moves to its final section covering streams, including how to
flatMap functions and processes onto streamed collections, including how efficient streams of primitive types are compared with their object-oriented friends.
Coverage of streams then moves into optional types, and how they can be chained/mapped, as well as the grouping operations that allow streams of data to be cut up and pivoted based on a particular desired data structure.
Finally, there is some discussion of the differences between processing streams sequentially and in parallel, and provides some advice as to what types of processing this is amenable to or otherwise.
Although this book claims to just talk about lambdas, it covers much that is new to Java 8. What it doesn’t talk about are some of the new APIs such as the
java.time package; but that’s not promised nor delivered in the book. However, the book does cover all of the syntax changes to the Java language, along with the new APIs in the
The only thing that is missing in the book is an index. If you have an electronic copy this may not be as relevant, since you can search through to find the reference that you’re looking for; but if you’re buying the paper copy then the chapter index at the beginning is the only cross-referencing you will find. Fortunately the chapters are sufficiently short and the internal headings make finding things relatively easy when you need to find something, provided that you can locate the right starting point of the chapter.
If you only have a weekend to pick up what’s new in the Java 8 language, this weekend read is a great start.
About the Book Author
Madhusudhan Konda - I am a Java Developer working in London, primarily with investment banks and financial organisations. I have been working on Java platform for over 15 years. Started as a C / C++ Programmer, I have quickly learned Java while studying my Masters at IIT Kharagpur, India. I instantly fell in love with the language and never looked back.