0Pricing
Groovy & Gradle: JVM Automation and Build Engineering · Pelajaran

Skrip Groovy & GShell

Pelajari cara menulis dan menjalankan skrip Groovy serta berinteraksi dengan konsol Groovy (GroovyShell).

Skrip Groovy & GShell adalah pelajaran Groovy & Gradle: JVM Automation and Build Engineering gratis di CoddyKit. Ini adalah pelajaran 3 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Groovy & Gradle: JVM Automation and Build Engineering, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Groovy & Gradle: JVM Automation and Build Engineering mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Groovy Scripts: Quick Automation

A Groovy script is just a file of code that runs directly — no main method required. Perfect for automation and quick utilities.

Simple Script Structure

A Groovy script needs no class or method wrapper — the file itself is the entry point. Just write your lines and run them.

println "Hello from a Groovy script!"
def name = "Coddy"
println "My name is $name"

Executing Groovy Scripts

Save your code with a .groovy extension, then run it from the terminal with groovy myScript.groovy. That is the whole workflow.

Script Example: Basic Calculation

This script adds two numbers and branches with an if — a quick taste of how natural and readable Groovy scripting feels.

def num1 = 10
def num2 = 5
def sum = num1 + num2
println "The sum of $num1 and $num2 is: $sum"

if (sum > 10) {
  println "That's a big sum!"
}

Getting User Input

Scripts can talk to the user too. Read a line from the console with System.in.newReader().readLine(), as shown below.

print "What's your name? "
def name = System.in.newReader().readLine()
println "Hello, $name! Welcome to Groovy."

Meet the GroovyShell (GShel)

The GroovyShell (groovysh) is an interactive console — run snippets instantly, test ideas, and get feedback without saving a file.

Launching GShell

Type groovysh to launch the interactive shell, or groovyConsole for the GUI version. We will stick with the command-line one here.

Your First GShell Commands

Inside groovysh, type any Groovy and it runs immediately, showing the result after ===>. Type :exit when you are done.

GShell: Beyond Code

GShell has colon commands for managing your session: :help, :history, :clear, and :reset to wipe declared variables.

Instant Code Testing

GShell shines for instant experiments — call a method or transform a list and see the result right away, no file, compile, or run step.

Script vs. GShell

Consider the following Groovy code snippet:

def x = 5
println x * 2

Where would you typically execute this snippet if you want to save it for later use and run it repeatedly?

Recap: Scripts & GShell

You learned the two core Groovy tools: scripts for repeatable .groovy files, and the GroovyShell for instant experimentation.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Skrip Groovy & GShell” gratis?

Ya — teks lengkap “Skrip Groovy & GShell” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Groovy & Gradle: JVM Automation and Build Engineering, upgrade ke CoddyKit PRO. Kursus Groovy & Gradle: JVM Automation and Build Engineering mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Skrip Groovy & GShell”?

Pelajari cara menulis dan menjalankan skrip Groovy serta berinteraksi dengan konsol Groovy (GroovyShell). Kamu berlatih Groovy & Gradle: JVM Automation and Build Engineering dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Groovy & Gradle: JVM Automation and Build Engineering?

Tidak diperlukan pengalaman sebelumnya. Groovy & Gradle: JVM Automation and Build Engineering di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 3 dari 4.

Berapa lama pelajaran “Skrip Groovy & GShell” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Groovy & Gradle: JVM Automation and Build Engineering ini?

Ya. Setiap pelajaran Groovy & Gradle: JVM Automation and Build Engineering menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Pengantar Groovy & JVM
  2. Sintaks & Tipe Dasar Groovy
  3. Skrip Groovy & GShell
  4. String Groovy & GString
← Kembali ke Groovy & Gradle: JVM Automation and Build Engineering