Getting Groovy Without The Bad Clothes
Written By: James Williams
- 20 Jul 2006 -
Description: This tutorial introduces you to Groovy, a dynamically-typed scripting language for the Java Virtual Machine, and runs you through creating your first script.
What is Groovy?
Groovy is a dynamically-typed scripting language for the Java Virtual Machine that serves the dual function of providing Java developers an easy entry point to scripting languages and the inverse for folks who use scripting languages.
How to get Groovy?
You can download Groovy at http://groovy.codehaus.org. To avoid having to run things in the same directory, it might be a good idea to add the location to the classpath. Inside the zip, you'll find the executables:
- groovy groovy interpreter for pre-made scripts
- groovyc compiles Groovy to Java byte code, afterwards the code can be run with the java keyword
- groovysh command-line interpreter
- groovyConsole GUI interpreter that allows loading and saving scripts
Why Groovy?
Why not use JRuby, Jython, or some other scripting language instead? You can, it's all a matter of choice. There is already a number of scripting languages, all of which have their own adherents and detractors, pros and cons.
Groovy is an good choice because it uses a Java-like syntax, can be embedded in Java, can be compiled down to byte code, and can inter-operate and subclass Java classes. The API relationship between Groovy and Java is like that of the major Romance languages (French, Spanish, Italian) but closer. Learning the first greatly reduces the barrier to entry of the second.