Java Reference
In-Depth Information
Chapter 1. Introduction
Before we begin our exploration of what lambda expressions are and how we can use them,
you should at least understand why they exist to begin with. In this chapter, I'll cover that
and also explain the structure and motivation of this topic.
Why Did They Need to Change Java Again?
Java 1.0 was released in January 1996, and the world of programming has changed quite a
bit since then. Businesses are requiring ever more complex applications, and most programs
are executed on machines with powerful multicore CPUs. The rise of Java Virtual Machines
(JVM), with efficient runtime compilers has meant that programmers can focus more on
writing clean, maintainable code, rather than on code that's efficiently using every CPU
clock cycle and every byte of memory.
The elephant in the room is the rise of multicore CPUs. Programming algorithms involving
locks is error-prone and time-consuming. The java.util.concurrent package and the
wealth of external libraries have developed a variety of concurrency abstractions that begin
to help programmers write code that performs well on multicore CPUs. Unfortunately, we
haven't gone far enough—until now.
There are limits to the level of abstractions that library writers can use in Java today. A good
example of this is the lack of efficient parallel operations over large collections of data. Java
8 allows you to write complex collection-processing algorithms, and simply by changing a
single method call you can efficiently execute this code on multicore CPUs. In order to en-
able writing of these kinds of bulk data parallel libraries, however, Java needed a new lan-
guage change: lambda expressions.
Of course there's a cost, in that you must learn to write and read lambda-enabled code, but
it's a good trade-off. It's easier for programmers to learn a small amount of new syntax and a
few new idioms than to have to handwrite a large quantity of complex thread-safe code.
Good libraries and frameworks have significantly reduced the cost and time associated with
developing enterprise business applications, and any barrier to developing easy-to-use and
efficient libraries should be removed.
Search WWH ::




Custom Search