Programmer's Wiki
Advertisement
16px-Pencil.png

Groovy is a scripting language built on the Java platform. Groovy code can either be run as an interpreted script or be compiled into Java bytecode, which can then be run anywhere that Java can. Because Groovy can use Java syntax and can use the same libraries it is very easy for Java Programmers to Learn.


Features[]

Closures[]

Closures are similar to methods. The biggest difference is that they can be assigned to variables so you can change what a Closure does at run time.

Closure example

def double = { it * 2 }

Function example

def double(n) { n * 2 }

Closures come with a default variable it (short for item) that is used when no name has been suggested.

Special Loops[]

10.times{println "Hello World"}

This loop will iterate 10 times

(0..10).each{println "Hello World"}

ranges are really lists so the each method can be used creating a simple loop.

Builders[]

Builders are a way of packaging Groovy code as a Domain specific language. There are a number of ways to create a builder. The easiest way seems to be to extend BuilderSupport.

SwingBuilder[]

SwingBuilder is a builder that helps create Swing-based graphical user interfaces (GUIs). Building Swing GUIs this way is far easier than the normal Java method.

AntBuilder[]

Builder that creates Ant scripts.

MarkupBuilder[]

Builder that creates XML or HTML output.

Notable Applications[]

Grails is a web development application which is similar to Ruby on Rails.

Groovy Examples[]

a number of algorithms have been implemented in groovy.


See Also[]

External Resources[]

Advertisement