Got Java? Get Groovy

Are you an experienced Java programmer who appreciates the hearty support of Java platforms and yet is envious of how quickly new languages such as Ruby can be used to build Web applications?

Now you can have the best of both worlds with an emerging language called Groovy, according to a presentation given last week at the Northern Virginia Java Users Group.

Groovy very closely resembles Java yet also has the dynamic nature of scripting languages such as Ruby or Python, said Michael Aube, a senior pre-sales engineer with CA Wily Technology, who made the presentation. Aube has also worked as a Java 2 Enterprise Edition architect.

Groovy uses the same object and runtime model as Java and handles class, inheritance, field and method definitions the same way. This allows Groovy programmers to use all Java APIs within their own code.

Because Groovy so closely resembles Java, Java programmers can get up to speed on Groovy quite quickly. Like many scripting languages ' and unlike Java itself ' Groovy allows for dynamic typing, or the freedom not to declare the specific data type a variable may be before the code is actually run.

As a result, the language is good for trying out new things quickly, Aube noted. 'It's ideal for rapid prototyping,' he said. You can run Groovy commands directly from a command line shell, or run Groovy scripts within a Groovy console.

'When you run a Groovy script [it is not interpreted], it is compiled down to the Java byte code and'runs inside the JVM," just like a Java Class, Aube said.

When you want to speed performance of the script, you can compile the Groovy code into a local class, Aube said. In this approach, each script is defined as its own class.

'When you program in Groovy, in many ways you're writing a special kind of Java. All the power of the Java platform ' including the massive set of available libraries ' is there to be harnessed,' noted authors Dierk Koenig, Andrew Glover, Paul King, Guillaume Laforge and Jon Skeet, in their book, 'Groovy in Action,' which Aube recommended.

Plus, Groovy offers a few additional features not yet found in Java,
most notably closures, which gives you the ability to build blocks of Groovy code on the fly without defining [them as part of] a class. You can assign these closures
to variables, pass them around as method arguments, and execute them at
arbitrary times.

James Strachan first created Groovy in 2004, and the language continues to be developed through volunteer efforts.

For the second part of the NoVAJUG presentation, fellow CA Wily Technology senior engineer Hugh Brien spoke about the benefits of Grails, a rapid Web application development framework based on Groovy.

Just as Ruby on Rails offers Ruby developers fast development through a preconfigured framework, so too does Grails offer a rapid development environment for Groovy. The advantage to Grails over Ruby on Rails, Brien said, is that a lot more people know Java than Ruby, so organizations may get their technical people up to speed a lot more quickly with Grails.

Additionally, the Grails framework can automatically generate a Web Archive (WAR) file for your Grails application, enabling you to drop that web application archive into any J2EE-compliant servlet container, such as those found in the Tomcat, JBoss, IBM WebSphere or BEA WebLogic application servers.

'Wherever I go, I see tons of Java. I see Java on mainframes, on Unix systems, on Windows,' Brien said, noting that The Java platform has long been a trusted environment used to run mission critical applications.

About the Author

Joab Jackson is the senior technology editor for Government Computer News.


  • Records management: Look beyond the NARA mandates

    Pandemic tests electronic records management

    Between the rush enable more virtual collaboration, stalled digitization of archived records and managing records that reside in datasets, records management executives are sorting through new challenges.

  • boy learning at home (Travelpixs/

    Tucson’s community wireless bridges the digital divide

    The city built cell sites at government-owned facilities such as fire departments and libraries that were already connected to Tucson’s existing fiber backbone.

Stay Connected