1 Getting Started With Groovy

Image taken from : groovy.codehaus.org

Groovy is an extension programming language from java(dynamic programming). It is about how do you write code more simple and more powerful without need to decrease the capability of java it self. For java programmers, I think to move into groovy will not be too hard because what did you do in java, you can do it in groovy without need to change anything. Moreover, we can make java code to be more simple. And still there are more capability that groovy can do besides those all. I’d like write them one by one through this blog.

But first let’s install groovy into our computer. To make it easy here I use windows operating system.

  1. Download the most recent stable groovy binary release from
  2. Extract groovy-binary x.x.x.zip to your hard drive location
  3. Set a GROOVY_HOME environment variable
  4. Add the %GROOVY_HOME%\bin to your system path

Usually all of process above can be processed automatically if you download groovy for windows installer. I think it will be easier without more effort.

Well let’s continue to next part. As I explain before, what you can do in java, you will be able to do it in groovy. Here is an example java code using POJO(Plain Old Java Object)/ java bean:

import java.util.List;

import java.util.ArrayList;

public class Employee{

String name;

String address;

String jobDescription;

public Employee(){}

public Employee(String name, String address, String jobDescription){

this.name = name;

this.address = address;

this.jobDescription = jobDescription;


public String getName(){

return name;


public void setName(String name){

this.name = name;


public String getAddress(){

return address;


public void setAddress(String address){

this.address = address;


public String getJobDescription(){

return jobDescription;


public void setJobDescription(String jobDescription){

this.jobDescription = jobDescription;


public static void main(String [] args){

List<Employee> employees = new ArrayList<>();

employees.add(new Employee("Achmad", "Jember", "Programmer"));

employees.add(new Employee("Fauzi", "Bangkalan", "Artist"));

employees.add(new Employee("Fauzi Achmad", "Jember", "Web Designer"));

for(Employee employee:employees){

System.out.println(employee.getName()+" "+employee.getAddress()+" "+employee.getJobDescription());




From source code above, we can convert it easily by changing the extension of Employee.java become Employee.groovy. to run it, we don’t have to complete then run, because groovy has done it once. This is the example.

Tagged: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: