Wikia

Programmer's Wiki

Groovy

Talk0
393pages on
this wiki

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 Edit

Closures Edit

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 Edit

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 Edit

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 Edit

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 Edit

Builder that creates Ant scripts.

MarkupBuilder Edit

Builder that creates XML or HTML output.

Notable Applications Edit

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

Groovy Examples Edit

a number of algorithms have been implemented in groovy.


See Also Edit

External ResourcesEdit

Around Wikia's network

Random Wiki