Jump to content

Apache Groovy

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by AxiomShell (talk | contribs) at 13:47, 27 April 2008 (External links: Added link to Groovy Zone news aggregator). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Groovy
File:Groovy groovy.png
Paradigmobject-oriented, scripting
Designed byJCP
DeveloperGuillaume Laforge (Project Manager and JSR-241 Spec Lead)
First appeared2003
Stable release
1.5.5 / April 14, 2008 (2008-04-14)
Typing disciplinedynamic, strong
OSCross platform (JVM)
LicenseApache License V2.0
Websitehttp://groovy.codehaus.org
Influenced by
Python, Ruby, Perl, Smalltalk, Java

Groovy is an object-oriented programming language for the Java Platform as an alternative to the Java programming language. It is an agile and dynamic language. It can be viewed as a scripting language for the Java Platform, as it has features similar to those of Python, Ruby, Perl, and Smalltalk.

Groovy uses a Java-like curly bracket syntax which is dynamically compiled to Java Virtual Machine bytecodes and which works seamlessly with other Java code and libraries. The Groovy compiler can be used to generate standard Java bytecode to be used by any Java project. Most Java code is valid Groovy syntax and can be used dynamically as a scripting language.

Groovy is currently undergoing standardization via the Java Community Process under JSR 241. Groovy 1.0 was released on January 2,2007.

Features

Groovy has a number of features not found in standard Java:

Syntax comparison

The following presents a side-by-side comparison of Java with Groovy:

Standard Java (Java 5+)

 for (String item : new String [] {"Rod", "Carlos", "Chris"}) {
     if (item.length() <= 4) {
         System.out.println(item);
     }
}

Groovy

 ["Rod", "Carlos", "Chris"].findAll{it.size() <= 4}.each{println it}

Markup language support

One noteworthy feature of Groovy is its native support for various markup languages such as XML and HTML. This feature enables the definition and manipulation of many types of heterogeneous data assets with a uniform syntax and programming methodology. For example:

the following Groovy code ...

    import groovy.xml.MarkupBuilder
    def myXMLDoc = new MarkupBuilder()
    myXMLDoc.workbook {
       worksheet(caption:"Employees") {
          row(fname:"John", lname:"McDoe")
          row(fname:"Nancy", lname:"Davolio")
       }
       worksheet(caption:"Products") {
          row(name:"Veeblefeetzer", id:"sku34510")
          row(name:"Prune Unit Zappa", id:"sku3a550")
       }
    }
    println myXMLDoc

... produces the XML result:

    <workbook>
       <worksheet caption='Employees'>
          <row fname="John" lname="McDoe" />
          <row fname="Nancy" lname="Davolio" />
       </worksheet>
       <worksheet caption='Products'>
          <row name="Veeblefeetzer" id="sku34510" />
          <row name="Prune Unit Zappa" id="sku3a550" />
       </worksheet>
    </workbook>

History

James Strachan first talked about the development of Groovy in his blog in August 2003. Several versions were released between 2004 and 2006. After the JCP standardization process began, the version numbering was changed and a version called "1.0" was released on Tuesday, January 2, 2007. After various betas and release candidates numbered 1.1, on December 7 2007 Groovy 1.1 Final was released and immediately rebranded as Groovy 1.5 as a reflection of the great improvement made.

See also

References

  • Koenig, Dierk (2006). Groovy in Action. Manning. ISBN 1-932394-84-2. {{cite book}}: Unknown parameter |coauthors= ignored (|author= suggested) (help)
  • Barclay, Kenneth. Groovy Programming: An Introduction for Java Developers. ISBN 978-0-12-372507-3. {{cite book}}: Unknown parameter |coauthors= ignored (|author= suggested) (help)
  • Groovy Recipes: Greasing the Wheels of Java. ISBN 978-0978739294.