Monthly Archives: January 2014

Closure in Java

According to Tom Hawtin

A closure is a block of code that can be referenced (and passed around) with access to the variables of the enclosing scope.

In programming languages, a closure (also lexical closure or function closure) is a function or reference to a function together with a referencing environment—a table storing a reference to each of the non-local variables (also called free variables or upvalues) of that function.

Pasted from <http://en.wikipedia.org/wiki/Closure_%28computer_science%29>

 JSR Proposal: Closures for Java

Summary: Add support so programs can operate on an arbitrary block of code with parameters, and simplify the use of methods that receive such blocks.

This JSR provides support for operating on an arbitrary “block of Java code”, or body, which is either a statement list, an expression, or a combination of both. We call the mechanism a closure expression. Wrapping statements or an expression in a closure expression does not change their meaning, but merely defers their execution. Evaluating a closure expression produces a closure object. The closure object can later be invoked, which results in execution of the body, yielding the value of the expression (if one was present) to the invoker. A closure expression can have parameters, which act as variables whose scope is the body. In this case the invoker of the closure object must provide compatible arguments, which become the values for the parameters.

In addition, this JSR may support a new invocation statement for methods that accept a closure to simplify their use in common cases.

Pasted from <http://www.javac.info/consensus-closures-jsr.html>

Since Java 1.1, anonymous inner class have provided this facility in a highly verbose manner. They also have a restriction of only being able to use final (and definitely assigned) local variables. (Note, even non-final local variables are in scope, but cannot be used.)

Java SE 8 is intended to have a more concise version of this for single-method interfaces*, called “lambdas”. Lambdas have much the same restrictions as anonymous inner classes, although some details vary randomly.

Lambdas are being developed under Project Lambda and JSR 335.

*Originally the design was more flexible allowing Single Abstract Methods (SAM) types. Unfortunately the new design is less flexible, but does attempt to justify allowing implementation within interfaces.

Pasted from <http://stackoverflow.com/questions/5443510/closure-in-java-7

References:

http://tronicek.blogspot.ae/2007/12/java-closures-tutorial.html

Bringing Closures to Java 5, 6 and 7 – http://mseifed.blogspot.se/2012/09/bringing-closures-to-java-5-6-and-7.html

Page Visitors: 300

Windows Task Manager – Enhanced

Have you felt at any point that Windows “Task Manager” is limiting in functionality? If so, this blog will try to give a solution by which you will have much better details on various programs running on your Windows machine with lots of data at your finger tips.

By the way I haven’t done anything in this blog by myself, rather I would just point to a simple utility which will help you get these details… :).

The tool we will be using is Windows Sysinternals Process Explorer. It is provided as a free download from Microsoft.

Process Explorer:

http://technet.microsoft.com/en-us/sysinternals/bb896653

You will need to download and unzip the Process Explorer package. The application does not have an installer, so unzip it somewhere convenient so that you can launch it when needed.

Complete details on the features of this simple program is detailed in the URL above.

Some screenshots which will make you use this enhanced Task Manager in Windows.

1 2 3 4

Page Visitors: 470

Apt way of upgrading any application – Branch By Abstraction

Recently I saw in a program in Television in which there was new technology developed by Japanese to destruct a building in a phased manner without noise, smell or dust in the middle of a crowded city.

The news article can be found here. For readers I am pasting the main content from this site for easy reading.

Grand Price Hotel Akasaka Japan
Grand Price Hotel Akasaka Japan

The Grand Prince Hotel in Akasaka which was built in the 1980s, previously stood tall at 460 feet until the Taisei Corporation demolished the building from the inside on a floor by floor basis, reportedly losing two floors every 10 days. The innovative Taisei Ecological Reproduction System (TECOREP) is a potentially efficient approach to deconstruction in densely built cities, also designed to recycle the energy pent up in a tall building. The top floor was reinforced by engineers with steel beams, and subsequently severed but kept in place to be used as an adjustable lid which could be lowered down on the building on an external support frame.

“In this demolition scheme, the building shrinks and disappears without you noticing,” said Hideki Ichihara, manager of the Taisei Corporation. “Dust pollution is cut by more than 90 percent, keeping the environmental impact very small.”

I watched the program and was amazed by it. Such a cool idea to destruct a structure as huge as this for me was awesome.

In the next few days I didn’t think of it and one fine day during an interacting session with my colleagues at office it was conceived that the current product on which we Software Engineers were working on needs uplift in technology and architectural aspects (overhauling). Since in Japan it was destruction which was done in a phased approach, I didn’t think there was any synergy that I could think of something like this in the case of a software application/product.

I then accidentally stepped on a recent article by Martin Fowler (Genius)in here. Suddenly I could see a co-relation or rather synergy between the Japanese way of building destruction with Martin Fowler’s way of uplifting/rejuvenating an existing software application/product.

I wouldn’t want to take any content out of his article and make my own article as no one in the world can write an article in such plain English as Martin. He explains this concept in such an easy manner that a lay man could easily get crux of what he wants to say.

There are some cool references in his article which also is  a definite read.

Page Visitors: 249