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.
Samples
A simple hello world script:
def name='World'; println "Hello $name!"
A more sophisticated version using Object Orientation:
class Greet {
def name
Greet(who) { name = who[0].toUpperCase() +
who[1..-1] }
def salute() { println "Hello $name!" }
}
g = new Greet('world') // create object
g.salute() // Output "Hello World!"
Leveraging existing Java libraries:
import static org.apache.commons.lang.WordUtils.*
class Greeter extends Greet {
Greeter(who) { name = capitalize(who) }
}
new Greeter('world').salute()
On the command line:
groovy -e "println 'Hello ' + args[0]" WorldMore information and Downloads on http://groovy.codehaus.org/
1 comments:
Nice :) but Groovy 1.5 was very very slow, and generally JRuby is much better and still faster (even that last Groovy 1.6-beta-1 release). So because Groovy is inspired by Ruby, for me JRuby is much better has better features and is more powerfull and faster.
Post a Comment