Groovy is an object
oriented programming language for the
an alternative to the Java programming language. It is a
dynamic language with features similar to those of
It can be used as a scripting language for the Java Platform
Groovy uses a Java
like parentheses syntax. It is dynamically compiled to
Java Virtual Machine byte code and works seamlessly with other Java
code and libraries. Most Java code is also syntactically valid Groovy.
Groovy 1.0 was released on January 2, 2007.
The Groovy language is largely a superset of the Java language. One can
usually rename a .java file to a .groovy one and it will work (though
there are a few incompatibilities). Groovy has a number of features not
found in standard Java. This makes the learning curve for Java
developer’s gradual, since they can start with Java syntax and gradually
learn to add Groovy features
Groovy is an agile and dynamic language for the Java Virtual
Groovy builds upon the strengths of Java but has additional power
features inspired by languages like Python, Ruby and Smalltalk
Groovy makes modern programming features available to Java
developers with almost
zero learning curve
Groovy supports Domain
Specific Languages and other compact
syntax so your code becomes easy to read and maintain
Groovy makes writing shell and build scripts easy with its powerful
processing primitives, OO abilities and an Ant DSL
Groovy increases developer productivity by reducing scaffolding
code when developing web, GUI, database or console applications
Groovy simplifies testing by supporting unit testing and mocking out
Groovy seamlessly integrates with all existing Java objects and
Groovy compiles straight to Java byte code so you can use it
anywhere you can use Java
Groovy features not available in Java include both static and
dynamic typing (with the def keyword), closures, operator
overloading, native syntax for lists and associative arrays
(maps), native support for regular expressions, polymorphic
iteration, expressions embedded inside strings, additional
helper methods, and the safe navigation operator "?." to
automatically check for nulls.
Groovy's syntax can be made far more compact than Java.
Groovy is its native support for various markup languages such
as XML and
, accomplished via an inline DOM syntax.
This feature enables the definition and manipulation of many
types of heterogeneous data assets with a uniform and concise
syntax and programming methodology.
One particular style of functional programming of
particular merit is to make use of lazy evaluation.
This allows you to define infinite structures , devise
particularly efficient solutions to certain kinds of
problems, and come up with very elegant solutions
to otherwise hard problems. The good news is that
several parts of Groovy already make use of this
style and they typically hide away the hard bits so
you don't need to know what magic is happening
on your behalf.
Groovy's SQL magic is found in an elegant API called GroovySql.
Using closures and iterators, GroovySql neatly shifts JDBC resource
management from you, the developer, to the Groovy framework. In so
doing, it removes the drudgery from JDBC programming so that you
can focus on queries and their results.
Just in case you've forgotten what a hassle normal Java JDBC
programming can be, I'm all too happy to remind you! In Listing 3,
you can see a simple JDBC programming example in the Java
Stored procedure calling and negative indexing can be essential
aspects of data manipulation. GroovySql makes stored procedure
calling as simple as using the call method on the Sql class. For
negative indexing, GroovySql provides its enhanced ResultSet type,
which works much like