| Free tutorials for Java, Eclipse and Web programming |
Version 1.4
Copyright © 2008 - 2011 Lars Vogel
08.02.2011
| Revision History | ||
|---|---|---|
| Revision 0.1 | 12.11.2008 | Lars Vogel |
| Created | ||
| Revision 0.2 - 1.4 | 02.12.2008 - 08.02.2011 | Lars Vogel |
| bug fixes and enhancements | ||
Groovy
This article gives a short overview of the Groovy language including collections, loops, gstrings, MOP, closures, operator overloading, XML handing and using Groovy together with Java class. It also describes how to use Eclipse for developing Groovy.
This article assumes that you have already Eclipse installed and that you have used Eclipse for Java development. This article was written using Groovy 1.7, Eclipse 3.6 (Helios) and Java 1.6.
Table of Contents
Groovy is a dynamic language which is based on the Java Virtual machine. Groovy supports standard Java constructs including annotations, generics, static imports, enums, varargs and in addition advanced language features as
Groovy is a dynamic language that runs on the JVM and is tightly integrated with the Java language. Groovy provides lots of simplifications compared to standard Java language features and advanced language features as properties, closures, native support for lists, maps and regular expressions, duck typing and the elvis operator.
Groovy is almost compatible to Java, e.g. almost every Java construct is valid Groovy coding which makes the usage of Groovy for an experience Java programmer easy.
The following assumes that you have already Java programming experience and focus on Groovy specific features.
While the simplicity and ease of use is the leading principle of Groovy here are a few nice features of Groovy:
Groovy allows to change classes and methods at runtime. For example if a class does not have a certain method and this method is called by another class the called class can decided what to do with this call.
Groovy does not require semicolons to separate commands if they are in different lines (separated by new-lines).
Groovy has list processing and regular expressions directly build into the language.
Groovy implements also the Builder Pattern which allows to create easily GUI's, XML Documents or Ant Tasks.
Asserts in Groovy will always be executed.