Sunday, October 7, 2012

Learning Linux Commands

I always had my development environment on Windows operating system so I never got a good hands-on on unix commands. This becomes a handicap when you have to troubleshoot a production issue once in a while as most of the time production environments are on Linux.

I have always been on the lookout for the ways to get a unix emulator or something similar on Windows. Earlier I tried Cygwin which is a good tool to get Linux look and feel environment on Windows. The only issue with this is that you have to install a large number of tools. On your workstations it may not be possible because of the restrictions imposed by employers.

Recently I stumbled upon another cool site called linuxzoo. I wish I had known about this site earlier. It allows you to have a remote private Linux machine with root access. This machine will be under your complete control, and you have to start it and stop it just like any normal machine!


So, If you are interested in learning Unix/Linux commands and you don't have access to Linux box get yourself registerd on http://linuxzoo.net.   Happy Learning!!

Tuesday, October 2, 2012

Say hello to Groovy - Part 3 (Collections)


In my previous blog i talked about various operators and control structures available in Groovy. Today i am going to talk about Groovy collections. Like Java, we have List and Map in Groovy. Groovy also has something called Range.

 
Lists

List is an ordered collection of objects. Groovy lists are indexed using [] operator. We can use [] to define an empty list and << to add items to a list.

Following code snippet shows how a list is defined in Groovy.

List Methods

Lists support many useful methods. Following code snippet illustrate the usage of some of the list methods.


Maps
Map is a collection of key value pair. We can use [:] to define an empty map. If the keys in a Map is String, it can act as a bean.
Following code snippet shows how to define and use Maps in Groovy.


Map Methods 
Maps support many useful methods. Following code snippet illustrate the usage of some of the Map methods.


Range

Range can be used to specify a list of sequential values. Range is defined using the first and last value of the sequence. Range can also be defined to exclude the last value. Use .. operator to include first and last value. Use ..< operator to exclude last value.

Ranges can be used for any Java object which implements java.lang.Comparable for comparison and also have methods next () and previous() to return the next / previous item in the range.

follwoing code snippet shows how to define and use Range in Groovy.

Range Methods

Like Lists and Maps, Range also support many useful methods. Following code snippet illustrate the usage of some of the Range methods.