Groovy (programming language)
File:Groovy groovy.png | |
Paradigm | Object-oriented, scripting |
---|---|
Appeared in | 2003 |
Designed by | JCP |
Developer | Guillaume Laforge (Project Manager and JSR-241 Spec Lead) |
Stable release | 1.7.0 (December 22, 2009 ) |
Typing discipline | Dynamic, strong, duck |
Influenced by | Java, Python, Ruby, Perl, Smalltalk, Objective-C |
OS | Cross platform (JVM) |
License | Apache License v2.0 |
Website | http://groovy.codehaus.org |
Groovy is an object-oriented programming language for the Java platform, and is the second standard language for the Java platform, the first being the Java programming language.[1] It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk. It can be used as a scripting language for the Java Platform.
Groovy uses a Java-like bracket syntax. It is dynamically compiled to Java Virtual Machine bytecode and works seamlessly with other Java code and libraries. Most Java code is also syntactically valid Groovy.
Groovy 1.0 was released on January 2, 2007.
Features
Some Groovy code looks like it would in the Java language, but Groovy is not a superset of Java. For instance, Groovy does not support Java's classic for loop syntax.[2] However, barring a few incompatibilities, one can usually rename a .java file to a .groovy one and it will work. Groovy allows the coder to leave out some elements which are required in Java, so Groovy code can be more compact.[3] This makes the Groovy learning curve for Java developers gradual, since they can start with Java syntax and gradually learn to add Groovy features.[4]
Groovy features not available in Java include both static and dynamic typing (with the def keyword), closures, operator overloading, native syntax for lists and associative arrays (maps), native support for regular expressions, polymorphic iteration, expressions embedded inside strings, additional helper methods, and the safe navigation operator "?." to automatically check for nulls (for example, "variable?.method()", or "variable?.field").[5]
Groovy's syntax can be made far more compact than Java. For example, a declaration in Standard Java 5+ such as:
for (String it : new String[] {"Rod", "Carlos", "Chris"})
if (it.length() <= 4)
System.out.println(it);
can be expressed in Groovy as:
["Rod", "Carlos", "Chris"].findAll{it.size() <= 4}.each{println it}
Groovy provides native support for various markup languages such as XML and HTML, accomplished via an inline DOM syntax. This feature enables the definition and manipulation of many types of heterogeneous data assets with a uniform and concise syntax and programming methodology.[citation needed]
Unlike Java, a Groovy source code file can be executed as an (uncompiled) script, if it contains code outside any class definition, or if it is a class with a main method, or is a Runnable or GroovyTestCase. But, unlike other script languages such as Ruby, a Groovy script is fully parsed, compiled, and generated before execution. (This occurs under the hood, and the compiled version is not saved as an artifact of the process.)[6]
GroovyBeans are Groovy's version of JavaBeans. Groovy implicitly generates accessor and mutator methods. In the following code, setColor(String color) and getColor() are implicitly generated; and the last two lines, which appear to access color directly, are actually calling the implicitly generated methods.[7]
class AGroovyBean {
String color
}
def myGroovyBean = new AGroovyBean()
myGroovyBean.setColor('baby blue')
assert myGroovyBean.getColor() == 'baby blue'
myGroovyBean.color = 'pewter'
assert myGroovyBean.color == 'pewter'
Groovy offers simple, consistent syntax for handling lists and maps, reminiscent of Java's array syntax.[8]
def movieList = ['Dersu Uzala', 'Ran', 'Seven Samurai'] //looks like an array, but is a list
assert movieList[2] == 'Seven Samurai'
movieList[3] = 'Casablanca' //adds an element to the list
assert movieList.size() == 4
def monthMap = [ 'January' : 31, 'February' : 28, 'March' : 31 ] //declares a map
assert monthMap['March'] == 31 //accesses an entry
monthMap['April'] = 30 //adds an entry to the map
assert monthMap.size() == 4
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.
Criticism
Groovy has been described as a "mistake" [9] after Strachan wrote on his blog [10]
I can honestly say if someone had shown me the Programming in Scala book by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy.
IDE support
Many integrated development environments support Groovy:
- Eclipse, through a plugin
- IntelliJ IDEA, through the Jet Groovy Plugin
- NetBeans, since version 6.5
- TextMate
See also
- Comparison of programming languages
- BeanShell
- Scala
- Grails (framework)
- Ruby
- JRuby
- Jython
- Boo
- Pnuts
- ZK Framework
- Project Zero
- Tellurium (software)
Notes
- ↑ König 2007, pg. 9
- ↑ König 2007, pg. 31
- ↑ König 2007, pg. 32
- ↑ http://groovyvan.wordpress.com/2007/11/27/edpovazan/
- ↑ http://groovy.codehaus.org/Differences+from+Java
- ↑ König 2007, pp. 37-8
- ↑ König 2007, pp. 38-9
- ↑ König 2007, pp. 41-3
- ↑ "The King Is Dead!? Long Live... Scala? Clojure?!". October 31, 2009. http://smuglispweeny.blogspot.com/2009/10/king-is-dead-long-live-scala-clojure.html. Retrieved 2009-12-29.
- ↑ "Scala as the long term replacement for java/javac?". July 6, 2009. http://macstrac.blogspot.com/2009/04/scala-as-long-term-replacement-for.html. Retrieved 2009-12-29.
References
- König, Dierk; Andrew Glover, Paul King, Guillaume Laforge and Jon Skeet (2006). Groovy in Action. Manning. ISBN 1-932394-84-2. http://www.manning.com/koenig/.
- Barclay, Kenneth; John Savage. Groovy Programming: An Introduction for Java Developers. ISBN 978-0-12-372507-3. http://www.elsevier.com/wps/find/bookdescription.cws_home/709814/description#description.
- Davis, Scott. Groovy Recipes: Greasing the Wheels of Java. ISBN 978-0978739294. http://www.amazon.com/Groovy-Recipes-Greasing-Wheels-Java/dp/0978739299.
- Subramaniam, Venkat. Programming Groovy: Dynamic Productivity for the Java Developer. ISBN 978-1934356098. http://www.amazon.com/Programming-Groovy-Productivity-Developer-Programmers/dp/1934356093/ref=sr_1_1?ie=UTF8&s=books&qid=1243439987&sr=8-1.
External links
Search Wiktionary | Look up groovy in Wiktionary, the free dictionary. |
- Official site
- JSR 241
- An introduction to Groovy
- Groovy at the Open Directory Project
- Groovy for the Office
- Groovy Zone - DZone Groovy news aggregator
- About Groovy - About Groovy & news
- Groovy articles directory
- Interview with Guillaume Laforge about Groovy, from QCon London 2007
- Interview with Guillaume Laforge and Graeme Rocher about Groovy and Grails, from SpringOne New Orleans 2009
ca:Groovy cs:Groovy de:Groovy es:Groovy (lenguaje de programación) fr:Groovy (langage) ko:그루비 it:Groovy ka:გრუვი nl:Groovy ja:Groovy pl:Groovy pt:Groovy ro:Groovy ru:Groovy sv:Groovy (programspråk) th:ภาษากรูวี tr:Groovy zh:Groovy
If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...
- Pages where expansion depth is exceeded
- Pages using deprecated source tags
- Pages with syntax highlighting errors
- Pages with broken file links
- All articles with unsourced statements
- Articles with unsourced statements from November 2008
- Articles with invalid date parameter in template
- Scripting languages
- Object-oriented programming languages
- Java programming language family
- Java specification requests
- JVM programming languages
- Curly bracket programming languages