Java 8 will go GA in March 2014. java8_logo The first proposed final draft of Java 8 JSR 337 was released early this week. One of the main components of this JSR is Lambda Expressions for the language (JSR 337). This brings the functional constructs to the language, which will undeniably make Java a top contender among other functional peers (Scala, Groovy, Clojure) on the JVM for Java developers. Conciseness is only part of the story, check out how Java 8 programs start to look with Lambda expressions. While being concise for a casual reader, it clearly makes a case why thinking functional may benefit to Java developers in terms of the powerful constructs it offers. The conciseness does not take away readability of the Java program, instead it makes Java developers feel home and enables functional programming with ease, taking away the heavy lifting usually required for moving away from OO paradigm.

I stole the name “Java.next” from Neal Ford‘s excellent series of articles about functional languages on the JVM. The latest installment of the series was “Java.next: Functional coding styles”. While, the article takes on legacy Java, adding Java 8 to the mix would not hurt. So, let us take his example where you are given a list of names, some of which consist of a single character. You are asked to return the names in a comma-delimited string that contains no single-letter names, with each name capitalized. Here are the various flavors of the implementation taken from the article, while Scala, Groovy and Clojure has its functional version, Java’s implementation is imperative and old school.

Java version:

Scala version:

Groovy version:

Clojure version:

Happy Holidays from the islands

Java 8 version of functional processing

With Java 8, functional interfaces makes this possible with Lambda expressions and Streams make you even more fun when working with Collections in Java 8. Here is the functional version in Java 8.

Switch it to parallelStream() for parallel processing, as simple as that to kick the tires of your cores.

My original intent was to compare with the Java.next languages as perceived by Neal Ford in his article. It is unfair to leave behind some of the cool languages on the JVM. Thanks Luke for bringing this up. I strongly believe top-notch IDE support (Eclipse or Intellij) is a win-win situation for users and language implementors. With that context, I updated my list to include Fantom, Gosu, Xtend, Kotlin, Ceylon in order of their age (oldest first).

Fantom version:

Gosu version

Xtend version:

Kotlin version:

Ceylon version:

Personally, I feel Java 8 and Groovy has better success rate in making developers stay in their comfort zone and still enjoy functional prowess. While, I agree Clojure and Scala versions make their case to different set of developers, I believe maintaining a larger code base will be a challenge, when time to develop and market is ever shrinking, and bringing someone up-to-speed with these language tricks will not be easy. If it looks good, eat it, does not play well when it comes to programming in general. While coming to the newer JVM languages, parallelism is one factor that makes Java 8 easy peasy to deal with. These new breed of languages bring ton of cool features (topic for another blog post!) and attracts developers to the JVM, not just Java developers, which is good for the platform. It remains to be seen in the coming years how well these languages get adopted in mainstream development.

Merry Christmas and Happy New Year everyone!

Update (12/29/2013) : Updated the Java.next languages comparison to include newer JVM languages: Fantom, Gosu, Xtend, Kotlin, Ceylon.

Possibly Related Posts:



Last week, JetBrains announced their new statically typed language Kotlin at the JVM Language Summit. Kotlin joins the elite group of statically typed languages : Scala, Gosu, Ceylon, Fantom, targeted to run on the JVM. Scala is the most mature in this statically typed landscape. Fantom supports static and dynamic typing, so it may not be directly competing with others. Both Ceylon and Kotlin are not publicly available yet, but the documentation can give you a preview of how these languages shape up. Kotlin definitely has the potential to attract Java developers due to its backing from the leading Java IDE maker. The good news is Kotlin will debut with an IDE support from day one, but this keeps expectations high on this project.

While Kotlin and Ceylon try to score on the “complexity attribute” of its mature competitor Scala, it may very well become a competitor to Java 8 from an adoption perspective. Java 8 will include support for the most sought after language feature Lambda is slated for late 2012 release. Both Ceylon and Kotlin plans to support higher order functions among others may have stable releases around that time frame. As these young languages are work in progress, it provides an excellent opportunity for them to receive constructive critique from the community and possibly fix or clarify their design choices. Given some of the features that could be implemented as compiler plugins in Kotlin makes it a perfect candidate for experimenting advanced language constructs that were once alien to Java.

Can Kotlin attract Java developers?

Well, it certainly has the potential to attract Java developers and you can already see huge interest from the developer community (Kotlin language documentation is already flooded with feedback) trying to understand what Kotlin can bring to the rapidly innovating JVM platform languages. Some blogs debate its cool new features and its approach to becoming the next big JVM language (NBJL). In addition to the cool features it plans to support, Kotlin incorporates some good idioms from Josh Bloch’s Effective Java. The language documentation references at least 10+ idioms from Effective Java which shows its commitment to adopting best practices that aid developer productivity and program maintainability. Here are some of those idioms highlighted in Kotlin documentation:

Item 11: Override clone judiciously
Item 14: In public classes, use accessor methods, not public fields
Item 16: Favor composition over inheritance
Item 17: Design and document for inheritance or else prohibit it
Item 18: Prefer interfaces to abstract classes
Item 23: Don’t use raw types in new code
Item 24: Eliminate unchecked warnings
Item 25: Prefer lists to arrays
Item 28: Use bounded wildcards to increase API flexibility
Item 38: Check parameters for validity
Item 43: Return empty arrays or collections, not nulls
Item 65: Don’t ignore exceptions
Item 69: Prefer concurrency utilities to wait and notify

Kotlin documentation by far is the most comprehensive source of information about the language and its syntax and it is well maintained. Once again JetBrains folks hit the right chord as the documentation is crucial for any language adoption early on. I do believe JetBrains would continue to deliver its promise of “Develop With Pleasure” with Kotlin too. So far, I have liked Kotlin’s approach to becoming the NBJL and its rich feature set and expressive syntax undoubtedly makes it a compelling choice for developers alike.

Possibly Related Posts: