Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

What is Groovy and in which cases we need Groovy?

 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am totally new to Groovy and just want to know that what is Groovy and in which cases we use them? Are there any special advantages to use Groovy?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most of what you are asking is answered on the Groovy home page.

You can already do just about anything in Java. With Groovy, you can still do those same things, but often with far less code.

For instance, a friend of mine was asked in an interview to use Java to find the intersection of two lists. This requires some thought using Java but I was able to solve and test this problem in a matter of seconds using Groovy:

Result: [1, 3, 5, 7]
 
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marc Peabody:
For instance, a friend of mine was asked in an interview to use Java to find the intersection of two lists. This requires some thought using Java but I was able to solve and test this problem in a matter of seconds using Groovy:

Result: [1, 3, 5, 7]



Or....


It is a few more characters of code, but it does speak for itself .
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great reply man.

I want to know that can groovy be used in the java classes itself or it is something like ANT. Is it integrable with java code. Can we use Groovy in between java code in methods?
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Himanshu Gupta:
I want to know that can groovy be used in the java classes itself or it is something like ANT. Is it integrable with java code. Can we use Groovy in between java code in methods?


You can create Groovy classes much like you can create Java classes. Groovy and Java both get compiled down to JVM bytecode, so you can call Groovy classes from your Java classes and vice versa.

On mixing Java and Groovy syntax in the same class file: you cannot put Groovy style code in the middle of a Java class. You can, however, put nearly any Java style code in the middle of a Groovy class.

A lot of the benefits of Groovy syntax are similar to what you can get from other JVM languages like JRuby.

I recommend downloading Groovy and playing around with the GroovyConsole using a few small tutorials. If you're already familiar with Swing in Java, you might especially have fun following some SwingBuilder Groovy tutorials.
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an issue with groovy that sometimes it does not spit proper exception messages which one would normally see when running Java programs.
 
Matthew Taylor
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Prad Dip:
I have an issue with groovy that sometimes it does not spit proper exception messages which one would normally see when running Java programs.



That is a common complaint among Java programmers migrating to Groovy. For the short term, you'll just have to get used to it . I know the Groovy devs have this issue in their sites, and would like to provide more succinct stacktraces.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Prad Dip:
I have an issue with groovy that sometimes it does not spit proper exception messages which one would normally see when running Java programs.


Which version of Groovy are you using? There's an exception sanitizer in the Groovy shell that I believe was put there not too incredibly long ago. I think the sanitizer was borrowed from the Grails project and really cleaned up a lot starting in Groovy 1.6.
 
Pradeep bhatt
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.5.6
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic