Tuesday Mar 25, 2014

Learn More About Lambda Expressions

Java SE 8 introduced Lambda Expressions, a powerful new behavior abstraction feature that enables code to be passed around as data. Lambda expressions make your code easier to read, easier to maintain, and less prone to error. Lambda expressions make it possible to express a problem with a higher level of abstraction than was previously possible. Use Lambda Expressions to eliminate large chunks of "boilerplate" code (such as when using inner classes to express behavior), and accomplish more work in less lines of code.

For more information about Lambda Expressions, see the following resources:

See What's New in JDK 8 for information about other new features in JDK 8.

Monday Mar 24, 2014

Learn More About Streams and Collections

Lambda Expressions are a major new language feature introduced in Java SE 8. Related to that change are the Streams API and Aggregate Operations on Collections. The Collection interface now exposes methods Stream<E> stream() and Stream<E> parallelStream(), for obtaining sequential or parallel streams from an underlying collection.

Here's a quick example showing how this new API (with Lambda Expressions) would be used in place of a traditional Iterator or for loop. It obtains a stream from the underlying collection, selects only red objects, then prints out the name of each object that was matched:

myShapesCollection.stream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));

Likewise, you could easily request a parallel stream, which might make sense if the collection is large enough and your computer has enough cores:

myShapesCollection.parallelStream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));

Using streams enables your code focus on "what" to do (instead of "how" to do it), leaving the library free to use whatever techniques it deems most appropriate (laziness, out-of-order execution, parallelism, etc.).

For more information on Lambda Expressions and Aggregate Operations, see the following resources:

See What's New in JDK 8 for information about other new features in JDK 8.

Wednesday Sep 25, 2013

JavaOne 2013: Lambda Expressions

Many conferences and hands-on lab sessions at JavaOne 2013 today feature lambda expressions, such as the following:

For more information about lambda expressions, see the following sections in the Java Tutorials:

Preview the Streams API in the java.util.stream package in the JDK 8 Early Access documentation.

Tuesday Sep 24, 2013

JavaOne 2013: Lambda: A Peek Under the Hood

Today, Java Language Architect Brian Goetz will give a presentation entitled "Lambda: A Peek Under the Hood." Lambda expressions (closures) and default methods are major additions to JDK 8, enabling new expressive opportunities for applications and libraries. This advanced session looks "under the hood" to explore how lambda expressions are implemented in JDK 8. See Lambda Expressions in the Java Tutorial for an introduction to these new language features.
About

Blog about Java technology documentation and news about Java releases.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today