blog rss feed

Getting groovy - an introduction to the Groovy language

Keywords:

Last editor: Dave Cherry, last modified: Aug 22, 2009

Introduction to the language

Groovy is a dynamic language that runs on the JVM. As such it can interact with any other java classes, and java classes can equally well interact with groovy classes. Groovy can also be scripted just like any other shell scripting language. Before we go any further discussing the groovy language, lets get groovy installed. This is fairly straightforward, and well explained on the groovy website. You can download groovy from the following location: http://groovy.codehaus.org

As this is explained on the above mentioned website, so we will not go into installation here. Once you've installed groovy make sure that you setup the following environment variables:

GROOVY_HOME the location where you installed groovy.
PATH Add GROOVY_HOME/bin to your path variable

Once you've set those variables, just start a command line and type groovysh, then you should see something similar to the following:

Let's get Groovy!
================
Version: 1.0 JVM: 1.6.0_01-b06
Type 'exit' to terminate the shell
Type 'help' for command help
Type 'go' to execute the statements

Following this is the command prompt,'groovy>'. At this prompt type the following, after each line pressing enter:

println "hello world"
go

After you execute go the following output is generated:

hello world
===> null

So what just happened?

You generated a script, one that printed out hello world, then returned null. This script was dynamically compiled into a class then executed on the JVM. Typing go in the console executes the script you've just typed in.

You can use the groovy command to execute scripts, assume a script named hello.groovy in the current directory, one would simply issue the following command:

groovy hello.groovy

This is the first part over, as you have seen, println is roughly equivalent to System.out.println in java. Next we start to look at objects and visibility.

Some may prefer to use groovyConsole in preference to groovysh, as groovy console starts a simple Swing UI.

1 2 3 4 >>

Comments [1]

On 19-Feb-2010 09:51,  Arvind wrote:

Ya this is very good article to get brief idea about groovy.

Thanks
Arvind

Please leave a comment



Search

Blog calendar

blog: previous month September 2010 blog: next month
su mo tu we th fr sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30