- running Groovy shell
groovish
Type 'help' or '\h' for help.
-----------------------------------------------------------------------------------------------------------
groovy:000>
you can e.g. type:
Sting.methods.each{println it.name }
- running graphic console
groovyConsole
- running uncompiled Grovy on web server
1. Add groovy.jar from $GROOVY_HOME/embedded to server classpath (WEB-INF/lib)
2. Add groovy.servlet.GroovyServlet to WEB-INF/web.xml.
3. Place your Groovy scripts wherever you'd normally place your JSP files.
4. Create hyperlinks to your Groovy scripts
- automatic imports
Groovy automatically imports:import packages:
java.lang.*
java.util.*
java.net.*
java.io.*
java.math.BigInteger
java.math.BigDecimal
groovy.lang.*
groovy.util.*
- method pointers
In Groovy you can do the following:
def shoppingList = []
def add = shoppingList.&add
def remove = shoppingList.&remove
add "Milk"
add "Bread"
add "Beer"
remove "Beer"
add "Apple Juice"
print shoppingList
- operators
The following are operators and corresponding methods:
Operator | Method |
a == b or a != b | a.equals(b) |
a+b | a.plus(b) |
a-b | a.minus(b) |
a*b | a.multiply(b) |
a/b | a.div(b) |
a%b | a.mod(b) |
a++ or ++a | a.next() |
a-- or --a | a.previous() |
a&b | a.and(b) |
a|b | a.or(b) |
a[b] | a.getAt(b) |
a[b] = c | a.putAt(b,c) |
a << b | a.leftShift(b) |
a >> b | a.rightShift(b) |
a < b or a > b or a <= b or a >= b | a.compareTo(b) |