This article is part 1 of a series on Java 8.
Java 8 is a giant step forward for the Java language. In Project Lambda, Java gets a new closure syntax (lambda expressions), method-references, and default and static methods on interfaces. It manages to add many of the features of functional languages without losing the clarity and simplicity Java developers have come to expect. In addition, many of the existing Java core library classes have been enhanced with the new Streams API.
This is a two part question: firstly why the word “lambda”; secondly, why do we need lambda expressions in Java?
You might of heard of Lambda Calculus. If not please watch this Jim W. talk (at least the first ten minutes). Lambda Calculus was invented around the same time as the Turing Machine, and they are computationally equivalent. They also represent a duality that has existed in computer science since it’s foundation. A duality reflected in “imperative” languages versus “functional” languages. So this is where the word “lambda” comes from.
However, there is a second and perhaps more important reason for lambdas - the rise of multi-core processors. It is widely acknowledged that functional programming (in conjunction with immutable data structures) makes parallel programming easier to accomplish. However, without lambda expressions, functional programming is clunky and inefficient in Java (although certainly not impossible). With lambda expressions, method-references, and functional additions to the Java core libraries, Java 8 supports some functional programming. It even supports parallel operations with the new Stream API.
In the next post, I’ll cover the syntax of lambdas, method references, and default methods.