0PricingLogin
Groovy & Gradle: JVM Automation and Build Engineering · Lesson

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

  1. Introduction to Groovy & JVM
  2. Groovy Syntax & Basic Types
  3. Groovy Scripts & GShell
  4. Groovy Strings & GStrings
← Back to Groovy & Gradle: JVM Automation and Build Engineering