File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes Advantages of Groovy over other scripting languages ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Advantages of Groovy over other scripting languages ?" Watch "Advantages of Groovy over other scripting languages ?" New topic
Author

Advantages of Groovy over other scripting languages ?

paul nisset
Ranch Hand

Joined: May 13, 2009
Posts: 177
Hi,
I'm curious about Groovy . It is described as a scripting language .
I understand that it compiles to Java code
Does this mean that you have to install a Groovy specific engine other than the JVM on your server like PHP does ?

What advantages are there to using Groovy over something like PHP, other than a familiarity with Java ?

Thanks,
Paul
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You need to install Groovy which generally means downloading a zip file, unzipping it somewhere and pointing your PATH to it's bin folder. You can execute groovy scripts directly from the command line using the 'groovy' executable. Or you can compile groovy into byte code and use it just like java code.

Groovy is nice because you can take advanatage of all the existing Java resources you already use every day. You just get to write less code to get your work done. I can't say that it has any advantages over PHP, or any other scripting language for that matter, because you should always use the right tool for the job. I'm sure in some situations PHP makes more sense. Of course, as a java developer, I'd be hard pressed to find that situation. ;)


GenRocket - Experts at Building Test Data
paul nisset
Ranch Hand

Joined: May 13, 2009
Posts: 177
Thanks for your input Gregg.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

I would beg to differ...Groovy works only in cases where your requirement is aligned with convention like CRUD. Anything more than that, you need to work on technology more than business matters - I guess it is waste of time.


===Vyas Sanzgiri===
My Blog
Peter Ledbrook
author
Greenhorn

Joined: Jul 15, 2009
Posts: 25
Hi,

I'm not that keen on the "scripting language" label. Yes, you can use it to write scripts, but that's not really its strength. Also, Groovy currently has a delay on starting up (similar to the one Java used to have in the old days), so it's not that great for writing scripts that you run from the command line.

I prefer the label "dynamic language" since it's more accurate. So you get full dynamic typing and you can change the behaviour of classes at runtime (for example by adding a method). The biggest advantage over both PHP and Ruby is that Groovy integrates so well with Java. You can even have a Java class refer to a Groovy class which refers to other Java classes. It also has the benefit of having very similar syntax to Java. If you have a Java infrastructure, then Groovy is usually the best option for dynamic languages. Before I get flamed, there is JRuby too, but I'm not sure what the status of its Java integration is.

One final thing: if you want to use Groovy as a scripting language, then you typically have to install Groovy locally. However, if you simply want to use it from a Java or Grails project, then the relevant JAR file is all you need (Grails already includes it).

Cheers,

Peter
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Vyas Sanzgiri wrote:I would beg to differ...Groovy works only in cases where your requirement is aligned with convention like CRUD. Anything more than that, you need to work on technology more than business matters - I guess it is waste of time.


I think you are talking about Grails here, which is more than Groovy. In any case, you're making false assumptions.
paul nisset
Ranch Hand

Joined: May 13, 2009
Posts: 177
Hi,

I appreciate everyone's input.
I found Peter's comment that it can link into Java apps via a jar file particularly useful .

I'm mainly curious about how it's used in a web application as opposed to a stand alone app
that you would run like "java myapp_with_main_method " .

Thanks,
Paul
Peter Ledbrook
author
Greenhorn

Joined: Jul 15, 2009
Posts: 25

I'm mainly curious about how it's used in a web application as opposed to a stand alone app
that you would run like "java myapp_with_main_method " .


You can use Groovy for anything that you might use Java for. It's XML processing is particularly strong. As an example, check out GroovyServlet:

http://groovy.codehaus.org/api/groovy/servlet/GroovyServlet.html

You just have to make sure that you use the Groovy compiler to compile the Groovy files. There is an Ant task you can use, or there is the GMaven plugin for Maven.

Hope that helps,

Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Advantages of Groovy over other scripting languages ?