Java 8 Officially Released With Lambda Support

Oracle officially releases Java 8, which is the first major upgrade in over two years for the platform

Oracle has announced the general availability Java Platform, Standard Edition 8 (Java SE 8), which promises to be a major feature release of the Java platform.

This release has been much anticipated as it was delayed while Oracle took time to secure the platform and work on other features. In fact, Java 8 is the first major release of Java since July 2011 when Oracle delivered Java 7. In addition to Java SE 8, Oracle also has made available the Java Developer Kit 8 (JDK 8) and the Java SE 8 Runtime Environment (JRE 8).

New Enhancements

Java 8 includes a slew of new features and enhancements, including enhanced developer productivity and significant application performance increases through reduced boilerplate code, improved collections and annotations, simpler parallel programming models and more efficient use of modern, multi-core processors.

Java questionPerhaps the biggest new feature in the Java 8 is support for Lambda expressions. Lambda expressions represent a new language feature introduced in Java SE 8. Lambda enable developers to treat functions as method arguments or code as data. Lambda expressions let you express instances of single-method interfaces – referred to as functional interfaces – more compactly. Method references provide easy-to-read lambda expressions for methods that already have a name.

“Java SE 8 is about taking advantage of new parallel architectures,” said Al Hilwa, an analyst with IDC. “Lambda, the key feature, opens the door for a new style of development that can lead to more parallelism and other capabilities like the Streams API are about parallel processing as well. The changes are significant for the community and for improving code quality everywhere in the long run.”

Regarding the new Stream API, classes in the new java.util.stream package provide a Stream API to support functional-style) operations such as Filter/Map/Reduce on streams of elements. The Stream API is integrated into the Collections API, which enables bulk operations on collections, such as sequential or parallel map-reduce transformations.

“Java 8’s lambdas look awesome,” said Charles Nutter, a core contributor to JRuby, which is an implementation of the Ruby language on the JVM. He added that the new support for lambda expressions is “as big a deal for Java the language as invokedynamic was for the VM.” The invokedynamic instruction simplifies and potentially improves implementations of compilers and runtime systems for dynamic languages on the JVM. In other words, it enables dynamic languages to run on the Java Virtual Machine.

Favourite Feature?

“Java has never tried to minimise your loc count,” said Matti Tahvonen, a developer at Vaadin, in a blog post on Java 8. “With good typing and nice code completions in IDEs, you don’t really need to minimise the amount of code you write. Maintainability and readability is commonly way more important than the amount of code. Still even, hardest Java fanatics have to confess that lots of keywords and symbols don’t necessary improve your code quality. Lambda support is one of the most visible enhancements in Java 8. In Vaadin developers’ daily work, lambdas mean a cleaner syntax for inline event listeners: any single method interface can now be expressed with a shorter lambda expression. From a library developers POI, this is a great change. Most commonly there are no changes needed to the libraries. Let me repeat myself: most core Vaadin API’s and add-ons can take advantage of lambdas today.”

Earlier this month, Typesafe, the company behind Scala, a functional programming language based on Java, released the results of a survey of more than 2,800 developers, where that 83 percent of respondents chose lambda expressions as their favourite feature of Java 8. The second most popular response was the improvements to the collections that are being added to exploit lambdas.

The Typesafe study also indicated that 65 percent of Java developers have plans to upgrade to Java 8 within the next 24 months, 54 percent plan to upgrade within the next 12 months, 29 percent plan to upgrade within the next six months, and only 1 percent of Java developers who have evaluated Java 8 have decided not to upgrade for the foreseeable future.

“This interesting snapshot of a sizable number of survey respondents suggests not only an intent to upgrade to Java 8 relatively quickly, but real interest in the new functional programming features it brings,” said Stephen O’Grady, principal analyst with RedMonk. “Such a transition to mainstream adoption would be typical of enterprise adoption patterns, which require technologies to prove themselves in high scale environments first.”

Gil Tene, CTO of Azul Systems, which builds Java runtime systems for business, said language enhancements alone make Java 8 a strong release.

“Java 8 is a very interesting new version for developers,” Tene said. “It has more features that matter to developers than any version of Java since Java 5, which introduced Generics. So I think people will be shifting to it faster. Lambda expressions are a key improvement to the language and I think it will help to drive Java 8 into the app platform quickly.”

“The biggest feature of Java 8 is the Lambda expressions or closures,” said Miko Matsumura, vice president of marketing and developer relations at Hazelcast. “This is the biggest change to the Java language since the beginning; it introduces concepts from functional programming. Closures have long been a part of functional languages like LISP and ML.”

Matsumura, who spent four years as the chief evangelist for the Java platform at Sun Microsystems, added, “Pretty much all of the lambda expression functionality was already available in Scala, plus other capabilities. However the addition of this capability in Java allows Java to modernize and to stave off some of the leakage of programmers to things like Scala.”

Moreover, from a libraries perspective, “the top things developers are excited about include things like new concurrency APIs. This is a big deal because of the trend towards massive parallelisation.”

Java Evolution

Also, consistent with the evolution of Java is the emphasis on readability, as more time and money is spent reading and understanding code than is spent writing it, Matsumura told eWEEK.

In addition to new security features and enhancements, other new features in Java 8 include Type Annotations, which provide the ability to apply an annotation anywhere a type is used, not just on a declaration. Used with a pluggable type system, this feature enables improved type checking of your code.

There also is a new Date & Time API, which is a set of packages that provide a comprehensive date-time model.

There is new JavaScript support in the form of Nashorn, a lightweight high-performance JavaScript runtime written in 100 percent pure Java, native on the JVM, that enables Java developers to embed JavaScript in Java applications.

The new Compact Profiles feature includes predefined subsets of the Java SE platform that enable applications that do not require the entire platform to be deployed and run on small devices.

Oracle also made usability improvements in Java Mission Control 5.3, which enables Java administrators and developers to more easily gather detailed low level information about how the JVM and the Java application are behaving.

And enhancements to JavaFX include an embedded specific graphics stack, new UI controls, a Modena theme, functionality to enable developers to embed Swing content into JavaFX applications, new 3D graphics features and additional HTML5 support.

“Over 400 of the more than 8,000 bug and enhancement issues addressed in JDK 8 were reported externally,” said Mark Reinhold, chief architect of the Java Platform Group at Oracle, in a blog post on the GA release of JDK 8. “These reports came in throughout the release cycle, enabled by our regular posting of weekly builds, but naturally the rate increased after we posted the Developer Preview build in September.”

Azul’s Tene said he hopes for the best with Java 8, particularly that developer begin to work with it early and “beat it up” to help get any kinks out.

Overall, he said Java 8 represents a good compromise by Oracle and the Java world. “I think they made the right compromise,” Tene said. ”Modularity was sacrificed and moved onto the next release, but that was just time management,” he added, referring to the modularity capabilities of Project Jigsaw, which will be in Java 9.

The goal of Project Jigsaw is to design and implement a standard module system for the Java SE Platform, and to apply that system to the platform itself and to the JDK.

“The team has done an excellent job pulling this together after so many years, especially given the ramp up on security investments,” IDC’s Hilwa said. “Overall Oracle has demonstrated good stewardship when you consider the needed investments and that all this goes into open source.”

Although Java 8 was officially released on 18 March, Oracle will host a major webcast on 25 March to formally launch the technology.

How well do you know open-source software? Take our quiz!

Originally published on eWeek.