Arthur Gassner's blog

… merely a personal blog …

Groovy: An elegant JVM-based language

leave a comment »

Being a Java developer for so many years, having programmed in Python recently and now having a look at Groovy, I am sure every Java developer must have a look at this elegant JVM-based language.

I have just started going through Groovy and I am feeling like programming in Java in a simpler way.

Take a look at how is easy to get a content from an url.

def url = new URL("http://ichart.finance.yahoo.com/table.csv?s=PETR4.SA")
url.eachLine { line ->
    println line.split(",")
}

In this example I got a csv file from an url and did a split in each line of the file.

What about working with dates and locales?

import static java.text.DateFormat.*
import static java.util.Locale.*

def today = new Date()
[ENGLISH, ITALY, FRANCE, GERMAN].each { loc ->
    println getDateInstance(FULL, loc).format(today)
}

Will print:

Tuesday, January 5, 2010
martedì 5 gennaio 2010
mardi 5 janvier 2010
Dienstag, 5. Januar 2010

Simple and elegant, isn’t it?

Much more at groovy website.

See you!

Advertisement

Written by agassner

January 5, 2010 at 7:10 pm

Posted in Tech Stuff

Tagged with , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.