Geek Igor

Java 8 Released

30 Mar 2014 on java

Whats new in Java 8? Where to start learning?

Last week we saw the new release of Java. Version 8 brings a lot of new features into the language. I think the most important are: - lambda expressions, - default method implementations in interfaces, - new datetime api.

There is also a lot of smaller improvements and additions in the standard library.

Lamdas FTW! Image from http://www.jamesiliff.com/speechless-protagonists-spatial-storytelling-and-immersive-worlds-half-life-game-narrative-review-at-gdc-2012

I’m a huge fan of the functional programming paradigm and of course I’m very excited about the release. Hope it will be quickly and widely adopted in production. Also the library improvements will make a compelling alternative to popular external libraries like JodaTime and Guava. This is good, because I think everybody were including them, even for small projects.

How to get start with Java 8?

If you want to dig into more details of lambdas in Java 8 check these two articles by Brianz Goetz: - http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html - http://cr.openjdk.java.net/~briangoetz/lambda/lambda-libraries-final.html

This is now Java (example from the latter)

Pattern pattern = Pattern.compile(\\s+");
Map<String, Integer> wordFreq =
    tracks.stream()
        .flatMap(t -> pattern.splitAsStream(t.name)) // Stream<String>
        .collect(groupingBy(s -> s.toUpperCase(),
            counting()));

Happy coding with Java 8!