Learn Java for Web Development

(Tina Meador) #1
399

Appendix B


Introduction to Groovy


Groovy is an agile and dynamic language for the Java Virtual Machine that builds upon the strengths of
Java but has additional powerful features inspired by languages such as Python, Ruby, and Smalltalk.
It seamlessly integrates with all existing Java classes and libraries and compiles to Java bytecode so
you can use it anywhere you can use Java. Groovy provides the ability to statically type check and
statically compile your code for robustness and performance and supports domain-specific languages
and other compact syntax so your code becomes easy to read and maintain.


Groovy makes modern programming features available to Java developers with almost zero learning
curve; increases developer productivity by reducing scaffolding code when developing web, GUI,
database, or console applications; and simplifies testing by supporting unit testing and mocking out
of the box.


Getting Started


Let’s start with a traditional “Hello World” program. But first you need to install Groovy. Groovy
comes bundled as a .zip file or platform-specific installer for Windows, Ubuntu, and Debian (as well
as openSUSE until recent versions). This section explains how to install the zipped version, since it
covers the most platforms.


To install Groovy, follow these steps:



  1. Download the most recent stable Groovy binary release .zip file from
    http://groovy.codehaus.org/Download.

  2. Uncompress groovy-binary-X.X.X.zip to your chosen location.

  3. Set a GROOVY_HOME environment variable to the directory in which you
    uncompressed the .zip file.

  4. Add the %GROOVY_HOME%\bin directory to your system path.

Free download pdf