I have been an avid follower of the technology radar by ThoughtWorks. Twice a year they evaluate a set of tools, languages, frameworks and put forth a summary. It usually gives me a good insight about where things are headed in the technology front.
This time, they have come up with a nice UI to represent their work. Here’s a snapshot of the radar chart that talks about the languages.
Last 2 weeks have been very exciting. The number of tools and technologies I have been working with is the reason for the excitement.
Ever since the magazine work began, I am on cloud nine. Literally on the cloud. I have been dabbling with Amazon Web Services extensively. Configured an EC2 Ubuntu instance and installed the necessary applications. Still working out the cost benefits of one feature over the other and fine tuning my setup.
Finally found time to upgrade to Mavericks OS X in my Mac.
I have started creating a number of Scala scripts for various mundane activities that were in my todo list for a long time.
Java 8 seems to be my favorite pass time as of now. Planning to write a number of posts on this topic.
Clients are keeping me busy with Sencha, Spring 4, NoSQL, iOS, Groovy/Grails and other JavaScript toolkits.
I started my new year by setting up Java 8 in my machine and playing with Lambda Expressions. Lambda expressions have been my favorite feature in C#. You can refer to some of my posts on Lambda expressions here.
Instead of adding more words to the never-ending information on Lambda expressions on the web let’s understand it with an example.
Let’s create an interface called Greetings with just one method like this.
If you want to create an instance of Greetings and invoke the print() method here’s the old way of doing things.
Greetings oldGreetings = new Greetings(){
public void print(String message){
System.out.println("Old greetings: " + message);
}
};
oldGreetings.print("Welcome 2014");
The output of this code is Old greetings: Welcome 2014. Now, you don’t want to be creating an anonymous inner class for this. Bring in Lambda expressions as shown here.
It cannot get simpler than this. Notice the use of -> in the code. newGreetings is a reference to a dynamically generated anonymous inner class object. When I try to print the class name of newGreetings it gives me Hello2014$$Lambda$1/518248. In other words newGreetings is an instance of what is called a Functional interface in Java 8. Hello2014 is the class with a main method where I created newGreetings. Here’s the complete code.
interface Greetings{
void print(String message);
}
public class Hello2014{
public static void main(String[] args){
Greetings oldGreetings = new Greetings(){
public void print(String message){
System.out.println("Old greetings: " + message);
}
};
oldGreetings.print("Welcome 2014");
Greetings newGreetings = message -> System.out.println("New greetings: " + message);
newGreetings.print("Welcome 2014");
System.out.println(newGreetings.getClass().getName());
}
}