Groovy (programming language)

From Wikipedia, the free encyclopedia

Jump to: navigation, search
Groovy
Image:Groovy groovy.png
Paradigm object-oriented, scripting
Appeared in 2003
Designed by JCP
Developer Guillaume Laforge (Project Manager and JSR-241 Spec Lead)
Latest release 1.5/ December 7, 2007
Typing discipline dynamic, strong
Influenced by Python, Ruby, Perl, Smalltalk, Java
OS Cross_platform (JVM)
License Apache License V2.0
Website groovy.codehaus.org

Groovy is an object-oriented programming language for the Java Platform as an alternative to the Java programming 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. In some contexts, the name JSR 241 is used as an alternate identifier for the Groovy language.

Groovy uses a Java-like curly bracket syntax which is dynamically compiled to JVM bytecodes and that 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. Groovy can also 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. After various betas and release candidates numbered 1.1, on December 7, 2007 Groovy 1.1 Final has been released and rebranded as Groovy 1.5 as a reflection of the great improvement made.


Contents

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

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}

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:

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

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.

Look up groovy in Wiktionary, the free dictionary.
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.