Thursday Aug 15, 2013

Trying Out Lambda Expressions in the Eclipse IDE

A new article, now up on otn/java, by Deepak Vohra, titled “Trying Out Lambda Expressions in the Eclipse IDE,” demonstrates how to take advantage of lambda expressions in Java SE 8 using the Eclipse IDE and virtual extension methods.

Vohra begins with the basics:
“Lambda expressions, also called closures, are a short-form replacement for anonymous classes. Lambda expressions simplify the use of interfaces that declare a single abstract method, which are also called functional interfaces. In Java SE 7, a single method interface can be implemented with one of the following options.
* Create a class that implements the interface.
* Create an anonymous class.”

Vohra explains that while lambda expressions can be used to implement a functional interface without creating a class or an anonymous class, they can be used only with interfaces that declare a single method.

Benefits of lambda expressions include:
* Concise syntax
* Method references and constructor references
* Reduced runtime overhead compared to anonymous classes

Vohra gets under the hood to explain the basics of lambda syntax, along with the nature of functional interfaces and target types, offering copious examples. All in all, the article offers a first-rate primer on how to make use of lambda expressions and virtual extension methods using the Eclipse IDE.

Check out the story here.

Thursday Jun 02, 2011

Managing Resources with Java 7

A very clear and detailed article by Julien Ponge, titled “Better Resource Management with Java SE 7: Beyond Syntactic Sugar,” presents the Java 7 answer to the automatic resource management problem in the form of a new language construct, proposed as part of Project Coin, called the try-with-resources statement.

Java applications frequently manipulate different types of resources such as files, streams, sockets, and database connections that require system resources for their operations. They must be managed with great care or risk having database connections and file descriptors remain open after an exception occurs elsewhere in the code. As a result, application servers may need frequent restarts due to resource exhaustion.

The article provides an overview of resource and exception management before explaining the essentials of try-with-resources statements. It then shows how a class can be made ready to support such statements, and concludes with a demystification of the syntactic sugar behind the language extension.

Ponge concludes that the try-with-resources construct “generates correct code on behalf of the developer, eliminating the need to write boilerplate code that is easy to get wrong. More importantly, this change has been accompanied with evolutions to attach one exception to another, thus providing an elegant solution to the well-known problem of exceptions masking each other.”

Read the rest of the article here.

About

Insider News from the Java Team at Oracle!

duke
javeone logo
Links


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
5
6
7
12
13
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today