Search⌘ K

Groovy for Java Devs

Discover the differences and similarities between Java and Groovy languages. Learn about Groovy’s unique syntax and practical tricks to improve your coding skills as a Java developer.

We'll cover the following...

Groovy vs. Java

Feature

Java

Groovy

Public Class

public class

class

Loops

for(Type it : c){…}

c.each {…}

Lists

List list = asList(1,2,3);

def list = [1,2,3]

Maps

Map m = …; m.put(x,y);

def m = [x: y]

Function Def.

void method(Type t) {}

def method(t) {}

Mutable Value

Type t

def t

Immutable Value

final Type t

final t

Null safety

(x == null ? null : x.y)

x?.y

Null replacement

(x == null ? “y” : x)

x ?: “y”

Sort

Collections.sort(list)

list.sort()

Wildcard import

import java.util.*;

import java.util.*

Var-args

(String… args) 

(String… args)

Type parameters

Class<T>

Class<T>

Concurrency

Fork/Join

GPars

...