The Java faithful gathered at JavaOne yesterday to hear about the future implementation of lambdas in the language. Also known as closures, this range of new capabilities for Java will have far-reaching implications for parallel applications.

Alex Buckley, specification lead for the Java language and virtual machine, spoke at length about the many ideas and solutions proposed to bring closures and better parallelization to Java. “Multicore hardware is now the default,” he said. “No one is surprised the new Amazon Kindle tablet is dual-core. To exploit this, Java needs to help people write software that parallelizes gracefully.

“The core of evolving the platform there needs to be better libraries. We believe this is where the work should occur because there are a lot of domain-specific concerns. As the Java language continues to grow in versions 7, 8 and 9, the features applicable to all libraries will benefit parallel libraries as much as everything else.”

Buckley said that many of the needed changes will take place in the Java Collections Library.

Daniel Smith, specification lead for Project Lambda, said that the inclusion of lambdas in Java will be accompanied by new capabilities in the core libraries of the language. “Now that we have extension methods in the language, we’re free to add a lot of extra functionality on top. We can have iterator methods,” he said.

Smith then introduced the map, reduce, filter and into functions, which can be used to iteratively run functionality across a set of data. “We’ve gotten to the declarative style, and we leave it to the libraries to perform the iteration for you,” he said. “The Collections know how to iterate themselves. That’s all we needed for things like filter and map. We haven’t needed to change the Collections implementation.

“The best practice for parallelizing some collection is to break it into pieces and perform some operation on these pieces and combine them up when done. That’s what fork/join gives us in OpenJDK 7. That’s an important enhancement we can use.”

Prerequisites for lambdas
Buckley said there are four main language evolutions that need to take place for lambdas to be viable in Java. The first is the need for functional interfaces, which Buckley described as “an interface with one method. We are defining this construct as a functional interface to remind ourselves that all these interfaces really express a function.”