Skip to content

Latest commit

 

History

History
93 lines (60 loc) · 2.81 KB

README.md

File metadata and controls

93 lines (60 loc) · 2.81 KB

Basic Info

Name: Groovy

Creator(s): James Strachan

Date: 2003

Website: groovy-lang.org

Intro

Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk. It can be used as both a programming language and a scripting language for the Java Platform, is compiled to Java virtual machine (JVM) bytecode, and interoperates seamlessly with other Java code and libraries. Groovy uses a curly-bracket syntax similar to Java's. Groovy supports closures, multiline strings, and expressions embedded in strings. Much of Groovy's power lies in its AST transformations, triggered through annotations.

Syntax

Variables in Groovy are declared using the variable type as a keyword followed by the name of the variable, an = sign and the value.

String name = "Jacob"
int num = 42
float pi = 3.14
Boolean groovy = true

If/Else statements in Groovy are very similar to other languages with the condition in brackets and the body inside curly braces.

Boolean groovy = true

if (groovy) {
    println("Groovy!")
} else {
    println("Not Groovy!")
}

Groovy provids a variaty of loop types, a simple for loop is shown below.

for (int i = 0; i < 10; i++) {
    println(i)
}

Functions in Groovy are called methods and are declared with the keyword def.

def area(width, length) {
    return width * length
}

println(area(12, 34))

Classes in Groovy are declared with the keyword class and initilized with the keyword new.

class Person {

    String name;

    def showName() {
        println(name)
    }

}

Person p1 = new Person();
p1.name = "Jacob";
p1.showName()

Libraries

  • Awesome Groovy ~ A curated list of awesome groovy libraries, frameworks and resources.

More Info