ITWissen.info - Tech know how online

Groovy

Groovy is an object-oriented scripting language first introduced in 2003 that runs on a Java Virtual Machine( JVM) and provides full access to all Java libraries. It is also possible to call Groovy code from a Java code and vice versa to integrate Java code from a Groovy script. Groovy goes back to the work of James Strachan, who developed a dynamically typed language with Groovy. Compared to Java, Groovy offers complementary language features and is influenced by the Python, Ruby and Smalltalklanguages. Groovy is a platform-independent open source software that has been available in version 1.6 since 2009. Plug-ins for Eclipse, Netbeans, IntelliJ IDEA, vim and Emacs are available as development environments.

Groovy as a Java implementation

Groovy is a Java implementation and realizes a lot of language features beyond the scope of Java, which thereby simplify working with Groovy. Thereby Groovy offers itself as a further standardized language for the Java Virtual Machine (JVM). By the Groovy compiler the scripts are translated first into Java byte code, so that these can be used also by arbitrarily other Java programs.

An interesting language feature are the so-called closures. With it code blocks are marked, which can be passed to a method for execution. The concept is comparable with the Anonymous-Inner-Classes existing in Java.

Groovy contains a comfortable support for the generation of Extensible Markup Language(XML), Hypertext Markup Language( HTML) and Document Object Model( DOM) of the World Wide Web Consortium(W3C) by means of so-called Markup objects, to which the structure to be generated is passed. These are syntactically closures that are executed on methods. With the MarkupBuilder arbitrary XML structures can be generated. Beyond that with the AntBuilder class a mechanism for the production of an Ant Scriptes is available. Likewise with the SwingBuilder class the condition for the simple conversion of graphic user surfaces is given.

Groovy makes also - again in the style of Java - the access to data bases possible. For this purpose, specific SQL statements are initiated via Groovy SQL, and the result can then be further processed with equally simple Groovy means. Furthermore, there are similar possibilities as with Java Server Pages( JSP) for the handling of server requests and HTML responses. This is ensured by so-called Groovlets, which enable the writing of Java servlets.

Grape for the management of code libraries

For the administration of code libraries the integrated tool Grape can be used. Already contained in the distribution is among other things the Groovy JmxBuilder, which can be used under use of the appropriate Groovy objects for the control of processes as Domain Specific Language( DSL). Parts of the distribution are also the modules GroovyLab, which supports a Domain Specific Language for mathematical applications similar to Matlab, or Groovy SOAP, which generates a SOAP server. For the creation of web applications, a framework is available with Grails. With GORM an Object-Relational Mapping persistence framework exists and with OCM Groovy mechanisms for an Object Content Mapping (OCM) implemented in Groovy for the mapping of the Java Content Repository (JCR) are available.

Since Groovy is still a fairly young language, it will initially be used for simple and not so complex tasks. Due to the convenient handling of BigDecimal and BigInteger, Groovy is mainly used in the field of financial mathematics.

Informations:
Englisch: Groovy
Updated at: 01.11.2013
#Words: 548
Links: object (O), Java, Java virtual machine (JVM), code, script
Translations: DE
Sharing:    

All rights reserved DATACOM Buchverlag GmbH © 2024