Groovy <ul><li>java made painless </li></ul><ul><li>ashish tonse </li></ul><ul><li>kaizen consulting </li></ul>
<ul><li>Dynamic Language for the JVM </li></ul><ul><li>Adds features from Python/Ruby/Smalltalk </li></ul><ul><li>Supports...
Where does it Work? <ul><li>Everywhere Java does (any JVM) </li></ul><ul><ul><li>J2EE, Swing, Spring, Seam </li></ul></ul>...
dynamic types (sort of) Value Java Type def a = “hello” String def a = 1 Integer def a = 1.5 BigDecimal def a = [1,2,3,4] ...
syntax sugar <ul><li>Semicolons optional </li></ul><ul><li>Multiple public classes in one file </li></ul><ul><li>== means ...
Collections: Lists <ul><li>def list = [1, 2, 3, 4]  </li></ul><ul><ul><li>list[2] == list.get(2) == 3 </li></ul></ul><ul><...
Collections: Maps <ul><li>def person = [name: “Ashish”, age: 27]  </li></ul><ul><li>person.name == “Ashish” </li></ul><ul>...
closures and blocks <ul><li>Closures are blocks of code </li></ul><ul><li>Can be passed as arguments to functions </li></ul>
Closures: Why useful? <ul><li>List newCourses = new ArrayList(); </li></ul><ul><li>for (Course c: courses) { </li></ul><ul...
Closures: Why useful? def newCourses = courses.findAll { course -> course.courseType == 3 }
Closures: Why useful? def newCourses = courses.findAll { it.courseType == 3 }
Reading XML <ul><li>Much less code than SAX/DOM/Stax </li></ul><ul><li>XmlParser, XmlSlurper </li></ul><ul><li>Access XML ...
Writing XML <ul><li>XML Builders </li></ul><ul><ul><li>DSL for building XML files </li></ul></ul><ul><ul><li>Code looks al...
How we can use Groovy <ul><li>GANT (Groovy Ant) build scripts </li></ul><ul><li>XML Processing </li></ul><ul><li>Seam Acti...
Gant: Groovy ANT includeTargets << gant.targets.Clean cleanPattern << [ '**/*~' ,  '**/*.bak' ] cleanDirectory << 'build' ...
GANT: Listing Tasks gant -p clean  Action the cleaning. clobber  Action the clobbering.  Do the cleaning first. otherStuff...
Seam Integration <ul><li>Full groovy integration within Seam </li></ul><ul><ul><li>Groovy actions and models </li></ul></u...
Spring Web Flows class BookController { ... def shoppingCartFlow = { showCart { on( &quot;checkout&quot; ).to  &quot;enter...
Questions <ul><li>Groovy online: groovy.codehaus.org </li></ul>
Upcoming SlideShare
Loading in...5
×

Groovy

372

Published on

Presentation introducing Groovy to a team of experienced J2EE developers

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
372
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Groovy"

  1. 1. Groovy <ul><li>java made painless </li></ul><ul><li>ashish tonse </li></ul><ul><li>kaizen consulting </li></ul>
  2. 2. <ul><li>Dynamic Language for the JVM </li></ul><ul><li>Adds features from Python/Ruby/Smalltalk </li></ul><ul><li>Supports Domain-specific Languages </li></ul><ul><li>Integrates with all Java objects </li></ul><ul><li>Compiles to Java bytecode (runs in the JVM) </li></ul>What is groovy?
  3. 3. Where does it Work? <ul><li>Everywhere Java does (any JVM) </li></ul><ul><ul><li>J2EE, Swing, Spring, Seam </li></ul></ul><ul><ul><li>Write JUnit tests </li></ul></ul><ul><ul><li>Develop with Eclipse (with debugging) </li></ul></ul>
  4. 4. dynamic types (sort of) Value Java Type def a = “hello” String def a = 1 Integer def a = 1.5 BigDecimal def a = [1,2,3,4] ArrayList def person = [name: “Ashish”, age: 27] LinkedHashMap
  5. 5. syntax sugar <ul><li>Semicolons optional </li></ul><ul><li>Multiple public classes in one file </li></ul><ul><li>== means equals() </li></ul><ul><li>Automatic getters and setters </li></ul>
  6. 6. Collections: Lists <ul><li>def list = [1, 2, 3, 4] </li></ul><ul><ul><li>list[2] == list.get(2) == 3 </li></ul></ul><ul><ul><li>list.add(5) </li></ul></ul>
  7. 7. Collections: Maps <ul><li>def person = [name: “Ashish”, age: 27] </li></ul><ul><li>person.name == “Ashish” </li></ul><ul><li>person[“age”] == 27 </li></ul>
  8. 8. closures and blocks <ul><li>Closures are blocks of code </li></ul><ul><li>Can be passed as arguments to functions </li></ul>
  9. 9. Closures: Why useful? <ul><li>List newCourses = new ArrayList(); </li></ul><ul><li>for (Course c: courses) { </li></ul><ul><li>if (c.getCourseType() == 3) </li></ul><ul><ul><li>newCourses.add(c); </li></ul></ul><ul><li>} </li></ul>
  10. 10. Closures: Why useful? def newCourses = courses.findAll { course -> course.courseType == 3 }
  11. 11. Closures: Why useful? def newCourses = courses.findAll { it.courseType == 3 }
  12. 12. Reading XML <ul><li>Much less code than SAX/DOM/Stax </li></ul><ul><li>XmlParser, XmlSlurper </li></ul><ul><li>Access XML using GPath (like XPath) </li></ul><ul><li>Supports Namespaces too </li></ul>
  13. 13. Writing XML <ul><li>XML Builders </li></ul><ul><ul><li>DSL for building XML files </li></ul></ul><ul><ul><li>Code looks almost exactly like XML result </li></ul></ul>
  14. 14. How we can use Groovy <ul><li>GANT (Groovy Ant) build scripts </li></ul><ul><li>XML Processing </li></ul><ul><li>Seam Actions </li></ul><ul><li>Spring WebFlow made Easier </li></ul>
  15. 15. Gant: Groovy ANT includeTargets << gant.targets.Clean cleanPattern << [ '**/*~' , '**/*.bak' ] cleanDirectory << 'build' target ( stuff : 'A target to do some stuff.' ) { println ( 'Stuff' ) depends ( clean ) echo ( message : 'A default message from Ant.' ) otherStuff ( ) } target ( otherStuff : 'A target to do some other stuff' ) { println ( 'OtherStuff' ) echo ( message : 'Another message from Ant.' ) clean ( ) } setDefaultTarget ( stuff )
  16. 16. GANT: Listing Tasks gant -p clean Action the cleaning. clobber Action the clobbering. Do the cleaning first. otherStuff A target to do some other stuff stuff A target to do some stuff. Default target is stuff.
  17. 17. Seam Integration <ul><li>Full groovy integration within Seam </li></ul><ul><ul><li>Groovy actions and models </li></ul></ul><ul><ul><li>src/model and src/action can contain .groovy files with same behavior </li></ul></ul><ul><ul><li>Hot Deployment (in debug mode) supported </li></ul></ul><ul><ul><li>seam-gen does not get disrupted </li></ul></ul>
  18. 18. Spring Web Flows class BookController { ... def shoppingCartFlow = { showCart { on( &quot;checkout&quot; ).to &quot;enterPersonalDetails&quot; on( &quot;continueShopping&quot; ).to &quot;displayCatalogue&quot; } ... displayCatalogue { redirect(controller: &quot;catalogue&quot; , action: &quot;show&quot; ) } displayInvoice() } }
  19. 19. Questions <ul><li>Groovy online: groovy.codehaus.org </li></ul>

×