Groovy

Groovy Installation



$ curl -s get.gvmtool.net | bash

$ source "/Users/uki/.gvm/bin/gvm-init.sh"

$ gvm install groovy

$ groovy -version

Groovy Version: 2.4.3 JVM: 1.7.0_79 Vendor: Oracle Corporation OS: Mac OS X

$ which groovy

/Users/uki/.gvm/groovy/current/bin/groovy


To add Groovy permanently to your Terminal  PATH

edit ~/.bash_profile
# Groovy updated May 19, 2015
export GROOVY_HOME=/Users/uki/.gvm/groovy/current
export PATH=${PATH}:${GROOVY_HOME}/bin


First Script


groovy_scripts $ cat hello.groovy 

println 'Hello from Groovy'
groovy_scripts $ groovy hello

Hello from Groovy




Groovy Console


Groovy Console is good for quick testing of Scripts, especially copy and paste from the Web.


$ groovyConsole








interface Alive{
   void alive()
}

class Creature implements Alive{
    def grawl() {
        println(" Grrrrrrrr!!! grawls the Creature")
    }
    void alive()
    {
        println(" Grrrrr!!! thinks the Creature")
    }
}

class Human extends Creature {
    String name;
    def sayHi(name) {
        println(" Hi, my name is $name! says the Human")
    }
   
    void alive()
    {
        println(" I am alive! says the Human")
    }
}



Creature me = new Human()
me.grawl()
me.alive()
me.name = "Uki"
me.sayHi me.name

Creature bear = new Creature();
bear.alive()


OUTPUT:

uki@ groovy_scripts $ groovy hello
 Grrrrrrrr!!! grawls the Creature
 I am alive! says the Human
 Hi, my name is Uki! says the Human

 Grrrrr!!! thinks the Creature



If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles