Code · 1 file

Sample Groovy File

Groovy is a dynamic JVM language used for Gradle builds and Jenkins pipelines. Every language sample implements the same small program so you can compare them side by side.

Groovy · 501 B

Sample Groovy file

An idiomatic Groovy example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.groovy — first linesGroovy
// Sample Groovy script — samplefiles.com
class Customer {
    int id
    String name
    BigDecimal balance

    boolean isVip() { balance >= 10_000 }
}

def customers = [
    new Customer(id: 1, name: 'Ada', balance: 12_500.00),
    new Customer(id: 2, name: 'Grace', balance: 830.50),
    new Customer(id: 3, name: 'Linus', balance: 10_000.00),
]

customers.each { c ->
    printf('%-6s %10.2f %s%n', c.name, c.balance, c.vip ? 'VIP' : '')
}
printf('Total: %.2f%n', customers.sum { it.balance })

File details

Size
501 B (501 bytes)
MIME type
text/x-groovy
SHA-256
abc0c4962d99079c495dc137b44ac552f5d845ef393d625d6d8ee6606dcbed8c
MD5
4d9f9511659023a008bf13788a2ca435

Download from the command line

curl -L -o sample.groovy https://files.samplefiles.com/code/groovy/sample.groovy

Or check the download in your browser with the checksum calculator.