Groovy and Java - The Integration Story

"Harold Meder" <[email protected]>
Newsgroups gmane.org.user-groups.trijug.juglist
Message-ID <[email protected]>
Groovy
It looks like Java ... but behaves like Ruby.
Grails is the Web Framework for Groovy.
GORM is the Grails Object Relations wrapper around Hibernate.
http://aboutGroovy.com

*Scott Davis presented "Groovy and Java - The Integration Story" at Monday's
TriJUG <**www.trijug.org* <http://www.trijug.org>*> meeting.*

Groovy is a dynamic (i.e., scripting) language.
But you don't have to learn a new language to use it.

It speaks Java!  OK.  Most of Java.  It does not understand for loops ...
yet.
Instead, collection.each{} is used ... just like Ruby.

So it's like Ruby?  Well, it supports about 85% of the Ruby concepts.

Groovy code can call Java code on the classpath.
Java code can execute Groovy code.
A POGO can implement a POJO Interface.
A POJO can implement a POGO Interface.

You get the best of Ruby, while still speaking Java.
It is catching up to Ruby and quickly learning the rest of the Java
language.

Groovy/Java - seamless interoperability.
It runs on the JVM, leveraging the underlying Java model to get integration
that is smooth and efficient.

Groovy can be compiled into bytecode.
Once you are finished taking advantage of the Groovy dynamic language
capabilities, groovyc will compile your Groovy code into a class file.
The JVM cannot tell the difference between a class file generated by groovyc
and a class file generated by javac.

POJO / POGO
javac / groovyc
JUnit TesCase / GroovyTestCase == JUnit TestCase
JSP / GSP
servelets / groovelets

Coberatura supports code coverage for Java / Groovy
Spring 2.0 treats Groovy as a first-class citizen
Struts 2.0, Tapestry and Drools have Groovy support.
Groovy has a native xml parser.

Groovy enhances developer velocity.
There is lots of syntactic gravy.  I.E., Groovy makes lots of logical
assumptions, but, if you insist, you can still be explicit.
 - methods are assumed to be public
 - attributes are are assumed to be private
 - primitives are automatically wrapped
 - returns are implicit
 - getters and setters are implicit
 - semi-colons are optional
 - System.out.println(...) is shortened to println(...)
 - "==" is assumed to mean .equals(...)

 - constructors can accept a variable number of parameters
   - parameters can be named
   - once named, parameters can be specified in any order
   - null parameters can be just dropped

 - Groovy is Duck-Typed
   - if it looks like a duck and acts like a duck, then it must be a duck
   - there is no need to cast it to use it ... just use it

 - Tired of closing connections?
   - Groovy assumes you want to close them on leaving the enclosing block of
code.

 - You don't have to unit test synthesized code.
   - For example, setters and getters are synthesized.
     Since you didn't write any getters and setters ...
     you don't have to write and test cases for them.

How do you get Groovy?
Just add a single jar file to your classpath.
Drop this jar file in your ant/lib and you can embed Groovy in your
build.xml.
Maven 2 also provides strong support for Groovy.

There is an eclipse plug-in for Groovy.
InteliJ 7.0 will have Groovy & Grails support
NetBeans & TextMate support Groovy

Not comfortable using Groovy for production code?
Use Groovy in your test cases.
Groovy has killer mocking support.

Groovy is ... well, Groovy!

_______________________________________________
Juglist mailing list
[email protected]
http://trijug.org/mailman/listinfo/juglist_trijug.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.