views:

1433

answers:

4
+9  Q: 

What is Groovy?

I have heard some things about Groovy from several different sources. One said Groovy is a great test harness for Java. Another said Groovy is Java's answer to Ruby. I am not sure what I've heard that is correct.

What is Groovy and why should I learn more about it? Obviously I have a vague idea about groovy, but the emphasis is on the why.

+16  A: 

Groovy is a dynamic language which runs on the Java platform. It has Java-like syntax, although it's not fully compatible with Java. (i.e. many Java programs are valid Groovy code, but not all.)

For more information, can I recommend Groovy in Action? Not that I'm biased or anything ;)

As for why you should learn it - if you know Java and you're interested in either scripting (it can be used for scripting, but doesn't have to be) or dynamic languages, it's a good starting point as you can keep a familiar syntax.

I first used it as an easy language to integrate into Ant - our Ant scripts didn't have quite enough power, and a bit of Groovy helped a lot.

Jon Skeet
+1 for the plug ;-}
ConcernedOfTunbridgeWells
One of the authors of this book seems to have a familiar name...Ah, yes, Gosling!
PhiLho
I would also highly recommend Groovy in Action, even though I'm not one of the book's authors. :)
Matt Passell
Pros: Groovy is easy to learn and answer for Ruby in Java worldCons: it's addicted :)
nightingale2k1
+7  A: 

Other people have covered the "what", so I'll just cover the "why":

Consider Groovy if you're looking for a scripting language with dynamic language features and must deploy your applications on a JVM. You might also want to look into JRuby and Jython as alternatives, although Groovy is more convenient if you're planning to frequently utilize Java libraries in your code.

Rob
Also, unlike with JRuby, all external libraries with Groovy will be same JAR files as you know from Java. No need to deal with different component packaging (gems) some of which may be depending on native code (as is often the case with JRuby).
Miro A.
+4  A: 

Groovy is great for writing unit tests for existing Java code.

Testing is an area where its advantages really shine, and where making experiments (like trying a new language) is low risk.

Also check out Grails for web development.

orip
+2  A: 

Groovy is a dynamically typed language that runs on the Java platform and includes some features that a lot of people wish were in Java (ex: closures). One nice thing about Groovy is that it reduces the amount of code needed to do common tasks such as parsing XML files and accessing databases. While learning Groovy you can always mix in straight Java code. This is nice since it allows you to ease into Groovy at your own pace while delivering functional code. If you've been using Java for a while I think you'll appreciate the simplicity of using Groovy since you can program more functionality using less keystrokes. The inclusion of closures was a big selling point for me. One word of caution: if you use Groovy for production code you should make sure there is descent test coverage (since Groovy is a dynamic language). Even if you decide not to use Groovy, it's not a huge time investment to learn and experiment a bit.

rich