Groovy
rename
Updated
2007-01-14 00:24
Basics
| Question | Answer |
|---|---|
| print a string | println "hi" |
| run a groovy script (from the command-line) | groovy hi.groovy |
| string with variable | "hi ${s}" |
| string with expression | "hi ${1 + 2}" |
| define a variable | def s |
| multi-line string | """foo bar""" |
| assert statement | assert s == "foo" |
Conventions used on this page
Several example variable names are used, for brevity. Assume the following variables have been defined:
String s, List l, Map m, File f, Object o (example misc object)
Groovy code has access to almost all standard Java classes and methods but I haven't, of course, listed them all here.
Terms / Things to remember
| Question | Answer |
|---|---|
| closure | block of code passed as a parameter |
| it | explicit variable passed to closure (if none are defined) |
| groovy-starter.conf (in conf/ dir) | file to list jars in |
| Groovlet | Groovy-ized servlet |
| GSP | Groovy-ized JSP |
| this.args | access command-line args |
| groovy.codehaus.org | Groovy home page |
Questions
| Question | Answer |
|---|---|
| no | are semicolons required? |
| yes | can semicolons be used? |
| yes | can groovy code use normal jars? |
| no in a script yes in a class | must variables be defined? |
| no | must method arg types be declared? |
| no | must exceptions be handled? |
| yes in a script | can code exist outside of a class |





