Groovy

groovy: An agile dynamic language for the Java Platform.

A quick introduction:


Installation:
1. It's zip file, just unzip it to some directory. For example: C:\groovy-1.7.2.
2. Go to C:\groovy-1.7.2\bin, execute groovyConsole.bat (windows) or groovyConsole (Unix).
3. Now you have a groovy console. Now this is what I need, I really don't have much interest to learn some new grammar, but GroovyConsole recognize the normal Java codes too, so I would like to use GroovyConsole as a Java Console. In this way, I could execute some simple Java codes directly in console.
4. How to add some existing library? Script->Add Jar to classpath or Add Directory to classpath.

For example, if I want to test some methods for StringUtils, I just need download the jar, and add it to classpath. Write some codes in Script console:

import org.apache.commons.lang.StringUtils;

String str = StringUtils.leftPad("999", 5, 'x');
System.out.println(str);

*****

Basically just treat the console as a Java file, the nice thing about it is you don't need to compile the codes.

Strange thing: seem Groovy Console doesn't like String[] stars = {"Tom", "Sam"};

But it's ok to use String[] stars = ["Tom", "Sam"];

System.out.println == println

println "${new Date()}"

****************************
class HelloWorld
{
def name
def greet() { "Hello ${name}" }
}

def helloWorld = new HelloWorld()

helloWorld.name = "Groovy"

println helloWorld.greet()