Contribute to this site!  (no login required)...      or  
Groovy

Directions (hide this section)

1. Click (memorize) in a memorizable table below, to begin a flashcard-like process
Try clicking (memorize) in both columns (to decide which side to start with)
2. Guess the answer in your head
3. Click the buttons and follow the directions at the bottom of the table
See Help for more detailed directions

Summary

Memorize keywords, tips and code snippets for Groovy, the Java-based scripting language.

 

 

Basics

Question Answer (memorize)
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 (memorize) Answer (memorize)
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 (memorize) Answer (memorize)
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

Lists

Question Answer (memorize)
create a list l = ["foo", "bar"]
append to list l << "third"
iterate through list for( e in list ) { ... }
join a list (into one string) l.join( "," )
access 2nd element (in a list) l[1]
shorthand for [3, 4, 5] 3..5
double list l * 2

Add a section to this page!

- Click this button to contribute to this page (by adding a section here).
♦  Feel free to experiment. Your edits won't immediately show up to everyone.

Memorize all (on this page)

Combines all tables on this page into one large table, and begins the memorization process:
 
the flashcard wiki anyone can edit!
the flashcard wiki anyone can edit!
working...
Terms of Use      Copyright memorizable.com 2007