News

What's Coming in Java 8: A 'Truly Revolutionary Upgrade' Featuring Lambda

"Java is back," Mark Reinhold, chief architect in Oracle's platform group, told attendees at this year's JavaOne conference Sunday. Reinhold led the technical keynote that has become a regular part of the JavaOne conference kickoff.

Reinhold used the technical keynote to give attendees a quick overview of the history of Java releases, concluding with Java 8, which he characterized as "truly revolutionary." He listed the new and updated features of the Java 8 release, including the new Date/Time API; Nashorn, which replaces Rhino; Type Annotations; and Compact Profiles, a first step toward modularization.

"Developers have many more choices and higher expectations," Reinhold said. "Java has to evolve to keep pace. Yet, for Java to continue to thrive, we have to maintain what James Gosling called the feel of Java. And this is hard; we can't just add feature after feature. We have to maintain the Java language and platform's key values of readability, simplicity, and universality. If we maintain those, Java will not only remain productive, but fun."

But without a doubt, the biggest change coming in Java 8 is Project Lambda (JSR 335), which supports programming in multicore environments by adding closures and related features to the language. Reinhold called it the single largest upgrade to the programming model, ever -- larger even than generics.

"It's the first time since the beginning of Java that we've done a carefully coordinated co-evolution of the virtual machine, the language, and the libraries all together," he said. "And yet the result still feels like Java."

Brian Goetz, Oracle's rockstar Java Language Architect, joined Reinhold onstage to explain Lambda.

"This is something that's going to change the way we all program in Java every day," Goetz said. "Programming well is about finding the right abstractions. We want the code that we write to look like the problem statement that it's trying to solve.... Java has always given us good tools for abstracting over data types, but where I want it to do better is abstracting over patterns of behavior, and that's where Lambda comes in."

Goetz showed how Lambda would work with a typical Java code sample, underscoring the "accidental detail" generated by the boilerplate stuff, and how the code doesn't readily reflect the problem statement, which can get in the way of understanding what's going on. The better way, as everyone knows, is to recognize that there's a behavior that can be abstracted over. But the tool for modeling behavior is inner classes, which results in even more boilerplate code.

"We tried to get rid of all this boiler plate by using abstraction, and we ended up with another kind of boilerplate," he said. "This is something that often makes people just give up and do it the dumb, ugly way, and we all lose for that."

"There's a poor beef-to-bun ratio here," Reinhold observed.

With Java 8, developers will be able to replace that inner class, which is just encoding a bit of behavior, with a Lambda expression, eliminating the boiler plate. But Lambdas are about more than just nicer syntax, Goetz insisted. Lambdas use the invoke dynamic feature (used by Nashorn) to get more compact byte code and higher performance code.

In addition to providing a nicer syntax, higher performance and better abstraction, Lambdas are also a key enabler of parallelism, Goetz pointed out. Lambdas make the code easier to write, easier to maintain, less error prone and parallel if you want it. Bottom line: it enables programmers to write better code.

But adding Lambda expressions to Java 8 had a side effect: it made the Collections API look especially long in the tooth. It forced the Oracle team to "bite the bullet," Goetz said, and addressed the problem of interface evolution. Their strategy: adding extension methods to existing interfaces while adding new interfaces retrofitted onto existing classes. The new Stream method, which Goetz demo'd, is one example.

Goetz directed attendees to the OpenJDK Project Lambda page as a great place to get up to speed on this essential Java upgrade.

About the Author

John K. Waters is a freelance author and journalist based in Silicon Valley. His latest book is The Everything Guide to Social Media. Follow John on Twitter, read his blog on ADTmag.com, check out his author page on Amazon, or e-mail him at john@watersworks.com.


comments powered by Disqus
Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.