Skip to main content
main-content

Über dieses Buch

Java Closures and Lambda introduces you to significant new changes to the Java language coming out of what is termed Project Lambda. These new changes make their debut in Java 8, and their highlight is the long-awaited support for lambda expressions in the Java language. You’ll learn to write lambda expressions and use them to create functional interfaces and default methods for evolving APIs, among many other uses.

The changes in Java 8 are significant. Syntax and usage of the language are changed considerably with the introduction of closures and lambda expressions. This book takes you through these important changes from introduction to mastery. Through a set of clear examples, you’ll learn to refactor existing code to take advantage of the new language features. You’ll learn what those features can do for you, and when they are best applied. You’ll learn to design and write new code having these important new features in mind from the very beginning.

Clearly explains the fantastic benefits resulting from Project Lambda Explains the syntax and IDE support for the new features Shows how to streamline your code by bringing some of the benefits of functional programming to the Java language Illustrates parallelism in closures through Stream and Spliterator objects Explains API evolution by adding methods to existing interfaces without breaking existing interface implementations, a technique addressing potential multiple inheritance issues

Inhaltsverzeichnis

Frontmatter

Chapter 1. Java 8: It’s a Whole New Java

This book is about lambdas (closures) in Java 8. More than that, though, it’s about the new language that Java has become. The revolution was not televised, and it was met with little fanfare, but it has happened. It is possible for you to continue to write the same old Java code in our new Java 8 world, but unless you get onboard with the revolution, you will increasingly discover code that is called “Java,” but which has language, syntax, and customs that are foreign to you.
Robert Fischer

Chapter 2. Understanding Lambdas in Java 8

The core new functionality in Java 8 is the introduction of lambdas. However, most introductions will show a couple of examples of lambdas, and then they leave it to the developer to figure out the rest. If you are going to be developing modern Java programs, however, you are going to need to be well versed in how lambdas can be used. Throughout this chapter, we will dig into the particularities of the syntax and semantics of lambdas, including how to create more complex lambdas, how to work with method calls and lambdas, and what this all looks like under the hood. We will also look at some classic ways to manipulate lambdas, and how they are implemented within Java. By the end of this chapter, you should be fluent in how to create the lambdas that you want.
Robert Fischer

Chapter 3. Lambda’s Domain: Collections, Maps, and Streams

In the last chapter, we saw how lambdas themselves work, but we explicitly focused on lambdas without creating a context for their use. We extracted lambdas from their natural environment in order to analyze them under a microscope. In this chapter, we will begin to see lambdas in the wild.
Robert Fischer

Chapter 4. I/O with Lambdas

So far, our exploration of lambdas and streams has existed in the well-controlled world of code. Sometimes, however, your code has to talk to the outside world. This chapter is where we enter into lambdas in the real world: instead of showing what is possible with lambdas in the abstract, we are getting into what programming with lambdas looks like in the grittiness of real code. This is a world where you end up having to work around a lot of unfortunate legacy code in Java, and where the nice theory and simple examples of lambdas give way to some of the gritty complexity. The important part for you is to understand how to work with that complexity in order to create a nicer development experience and more productive, stable code.
Robert Fischer

Chapter 5. Data Access with Lambdas

In the last chapter, we saw how lambdas enable us to work with files and streams. In this chapter, we will look at interacting with the database. Way back in chapter 1, we saw how lambdas can help Spring’s JDBCTemplate by making it easy to implement its callback interfaces. In chapter 3, we were introduced to streams, and in chapter 4, we saw how streams can make it easier to work with file data. In this chapter, we will see the specifics of working with Java’s data access structures (the java.sql package). This will give us an opportunity to meet another new data structure in Java 8’s standard library: the spliterator.
Robert Fischer

Chapter 6. Lambda Concurrency

The Java programming language is, at its core, a series of instructions. These instructions are executed in sequence. By default, you only ever have one of these series going at a time. However, if you have multiple processing cores on your machine, or if you have any kind of I/O, then this single series of instructions suddenly becomes very inefficient. If your program has a lot to do, but its single stream has to wait for the “read” I/O instruction to complete before doing anything else, then your program is wasting time. If you have four processing cores, but only one stream of instructions, then you are at best only using a quarter of your potential power. The solution to this is to have multiple streams of instructions executing at the same time within your program, which is called concurrency.
Robert Fischer

Chapter 7. Lambdas and Legacy Code

At this point in this book, you have seen all the wonderful things that lambdas can do for your codebase. But what about the huge pile of legacy code that is out there? There is a lot of code to be merged into this new reality, and a lot of Java developers are commited to projects that have to drag forward those balls of mud. How can lambdas make their life easier?
Robert Fischer

Chapter 8. Lambdas in Java Bytecode

This chapter is for those who want to go deeper and understand how lambdas really work. This is your red pill vs. blue pill moment: do you want to live in a world where Java has lambdas and they work great and everything is slick and awesome, or do you want to see what is really going on beneath the surface and discover the magic of the compiler pulls? If you are happy with the lambdas as you know and love them, then skip this chapter and enjoy. If you need to know what your code really means, then hold on tight: it’s time to go down the rabbit hole.
Robert Fischer

Appendix A. A Tour of Paradigms

Many books, articles, and conversations will wax poetic about programming language paradigms, comparing and contrasting “imperative,” “object-oriented,” and “functional” without explaining what they are. Worse, when people go to explain these particular styles, the result is often rather vague. This appendix will provide an overview of the three dominant paradigms in post-functional programming by implementing the same functionality three different ways: we will use a database set-up process as a common problem, and show how you would solve that problem in each of the different paradigms. All of this will be done directly from within Java, so you can see how Java looks when forced to be strongly in one single paradigm. At the end of the chapter, we will highlight some additional programming paradigms and styles so that you are at least familiar with the terms.
Robert Fischer

Backmatter

Weitere Informationen

Premium Partner

BranchenIndex Online

Die B2B-Firmensuche für Industrie und Wirtschaft: Kostenfrei in Firmenprofilen nach Lieferanten, Herstellern, Dienstleistern und Händlern recherchieren.

Whitepaper

- ANZEIGE -

Best Practices für die Mitarbeiter-Partizipation in der Produktentwicklung

Unternehmen haben das Innovationspotenzial der eigenen Mitarbeiter auch außerhalb der F&E-Abteilung erkannt. Viele Initiativen zur Partizipation scheitern in der Praxis jedoch häufig. Lesen Sie hier  - basierend auf einer qualitativ-explorativen Expertenstudie - mehr über die wesentlichen Problemfelder der mitarbeiterzentrierten Produktentwicklung und profitieren Sie von konkreten Handlungsempfehlungen aus der Praxis.
Jetzt gratis downloaden!

Bildnachweise