HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to GroovyVariablesData TypesOperatorsStringsListsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Map
🔀 Condition & Loop
🧩 Function
Groovy›Introduction to Groovy

Introduction to Groovy

First step into Groovy, the simple scripting language of the JVM: printing with println and comments.

Simple enough for a 5-year-old to understand

print with println

Groovy is simple: classes/main and semicolons are not required. println prints to the screen and moves to the next line.

Your first program
1
println "Hello!"
You don't even need parentheses.
Output / InputYou don't even need parentheses.
Output / Input
💡 Hint: In Groovy, parentheses and semicolons are mostly optional.

Comment line

Example code
1
// This is a comment — does not run.
Single-line comment with //.
CommentSingle-line comment with //.
2
println "Code is here"
Only this line runs.
Output / InputOnly this line runs.
CommentOutput / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

Groovy is a language that runs on the Java virtual machine and aims to make Java more concise. It emerged in 2003; most valid Java code is also valid Groovy code, which makes migration very easy.

Today, Groovy's most common use case is build scripts. Gradle configuration files are written in Groovy, and Jenkins pipeline definitions also use the same language. These two tools make working in the Java world difficult without knowing Groovy.

The language is dynamically typed, but you can declare types if you want. This duality defines Groovy's character: you skip writing types when writing quick scripts, and you gain safety by declaring types in large codebases.

What you will learn

  • how a Groovy script works
  • printing to the screen with println
  • that semicolons are optional
  • Writing comment lines
  • the limits of compatibility with Java

Who is this for?

  • those who write Gradle or Jenkins configurations
  • those who know Java and want to write shorter scripts
  • those looking for a dynamic language on the JVM

When to use?

Groovy is well-suited for build scripts, automation pipelines, and flexible configuration layers to be added to Java projects.

It is not preferred for performance-critical or large-scale application code; dynamic dispatch brings an overhead compared to Java.

Common mistakes

Wrong

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello")
  }
}

This code works, but it is redundant: you don't need to write a class and a main method in Groovy scripts. The file itself runs as a script. This boilerplate written out of Java habit completely wastes the conciseness provided by Groovy.

Correct

println "Hello"

Wrong

def ad = 'Ayşe'
println 'Merhaba $ad'

Variables inside single quotes are not replaced with their values; the variable name is printed on the screen verbatim along with the dollar sign. In Groovy, templates only work with double quotes. This is because it is one of the few languages where the quote type carries meaning.

Correct

def ad = 'Ayşe'
println "Merhaba $ad"

Wrong

println("one");;
println("two")

There is no syntax error here, but using semicolons is redundant and goes against the Groovy style. The language treats the end of a line as the statement boundary; semicolons written out of habit from Java clutter the code and reduce readability.

Correct

println "one"
println "two"

Frequently asked questions

Does every Java code run in Groovy?

Most do, but there are exceptions: array definition syntax, some inner class usages, and the behavior of the equality operator are different. When copying Java code, one must pay special attention to equality comparisons.

Do I have to write parentheses?

Parentheses are optional for method calls taking at least one argument; this allows configuration scripts to resemble natural language. However, parentheses are mandatory for calls without arguments and where there is ambiguity.

Between Groovy and Kotlin, which one should I choose?

If you are writing build scripts and automation, Groovy is more appropriate; if you are writing application code, Kotlin is more suitable. Kotlin is statically typed and has strong compiler support; Groovy's advantage is its dynamic flexibility and existing tool ecosystem.

Summary

Classes and a main method are not required in scripts.

Templates only work with double quotes.

Semicolons are optional.

Most Java code also runs in Groovy.

Gradle and Jenkins use Groovy.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code