Groovy Syntax & Basic Types
Understand Groovy's relaxed syntax, dynamic typing, common data types, and operators.
Groovy's Relaxed Style
Groovy's syntax is deliberately relaxed — you can skip a lot of what Java forces on you and write the same logic in far fewer lines.
Optional Semicolons & Parens
Two big relaxations: semicolons are optional, and parentheses around method arguments often are too. The code below shows both.
public class Main {
// Define a simple static method for demonstration
static void printMessage(String msg) {
System.out.println(msg)
}
public static void main(String[] args) {
// Semicolons are optional at the end of a line
System.out.println("Hello from Groovy")
System.out.println("CoddyKit makes learning fun") // Semicolon also optional
// Parentheses for method calls with arguments can be omitted
printMessage "Less typing, more coding!" // Calling without parentheses
printMessage("It's concise!") // Calling with parentheses
}
}All lessons in this course
- Introduction to Groovy & JVM
- Groovy Syntax & Basic Types
- Groovy Scripts & GShell
- Groovy Strings & GStrings