SlideShare a Scribd company logo
1 of 37
Download to read offline
1
              Groovy and Grails




                 What are they, and what are
                   the benefits and risks?



Spring Framework Meeting, 14 June 2008
2
              Who am I?

                John Leach, Chief Technical Officer for Syger
                   Java developer from the start – and still learning
                Syger - a small software consultancy in Verona, Italy

              Who are you?
                Who's heard of Groovy?
                Who's heard of Grails?
                Who writes web applications?

              Pleased to meet you
                Warning! Intensive content session
                  Lots to see, not much time
                Questions at the end

Spring Framework Meeting, 14 June 2008
3
              Overview of


                        Dynamic scripting language
                        Similar syntax to Java
                        Evolution not revolution

                        But...
                           with closures
                           and meta programming
                           and relaxed typing
                           and lots of syntax sugar
                           and a silly name - sigh




Spring Framework Meeting, 14 June 2008
4
              Overview of


       Ruby on Rails philosophy – evolution not revolution
       Convention over configuration
       Uses 20% Groovy and 80% Java (elegance and power)

       But...
          with Spring, Hibernate, and SiteMesh
          has a plugin architecture
          no XML (though it's there when you need it)
          no HQL/SQL (though they're there when you need them)
          no Ruby, JRuby or Rails




Spring Framework Meeting, 14 June 2008
5
              Java to Groovy – Step 1 HelloWorld.groovy

                public class HelloWorld {
                  private String name;

                    public void setName(String name) {
                      this.name = name;
                    }
                    public String getName() {
                      return name;
                    }
                    public String greet() {
                      return quot;Hello quot; + name;
                    }
                    public static void main(String... args) {
                      HelloWorld helloWorld = new HelloWorld();
                      helloWorld.setName(quot;Groovyquot;);
                      System.out.println(helloWorld.greet());
                    }
                }

Spring Framework Meeting, 14 June 2008
6
              Java to Groovy – Step 2 HelloWorld.groovy

                class HelloWorld {
                  String name

                    String greet() {
                      return quot;Hello quot; + name
                    }

                    static void main(String... args) {
                      HelloWorld helloWorld = new HelloWorld()
                      helloWorld.name = 'Groovy'
                      println(helloWorld.greet())
                    }
                }




Spring Framework Meeting, 14 June 2008
7
              Java to Groovy – Step 3 HelloWorld.groovy

                class HelloWorld {
                  String name

                    String greet() {
                      quot;Hello ${name}quot;
                    }

                    static void main(String... args) {
                      println new HelloWorld(name: 'Groovy').greet()
                    }
                }

                            Plain Ordinary Groovy Objects
                               Reduced clutter
                               Simple constructors
     Adapted from: http://groovy.dzone.com/news/java-groovy-few-easy-steps


Spring Framework Meeting, 14 June 2008
8
              Java to Groovy – Check HelloWorld.class

Groovy: JUGSardegna>groovy HelloWorld.groovy
        Hello Groovy

  Java: JUGSardegna>groovyc HelloWorld.groovy
        JUGSardegna>java -cp %GROOVY_HOME%embeddablegroovy-all-1.5.4.jar;.
         HelloWorld
        Hello Groovy

 Javap: JUGSardegna>javap HelloWorld
        Compiled from quot;HelloWorld.groovyquot;
        public class HelloWorld extends java.lang.Object
                implements groovy.lang.GroovyObject {
            public HelloWorld();
            public java.lang.String greet();
            public java.lang.String getName();
            public void setName(java.lang.String);
            public static java.lang.Object main(java.lang.String[]);
            ...
        }


Spring Framework Meeting, 14 June 2008
9
              Groovy Closures – Step 1 ListTests.groovy
import   static java.lang.System.out;
import   static java.util.Arrays.asList;
import   java.util.ArrayList;
import   java.util.List;

public class ListTests {
   public static void main(String... args) {
      List<String> names = asList(quot;Tedquot;, quot;Fredquot;, quot;Jedquot;, quot;Nedquot;);
      out.println(names.getClass().toString() + quot; quot; + names);
      List<String> shortNames = new ArrayList<String>();
      for(String s : names) {
        if (s.length() < 4) {            JUGSardegna>groovy ListTests.groovy
           shortNames.add(s);            class java.util.Arrays$ArrayList
        }                                  [quot;Tedquot;, quot;Fredquot;, quot;Jedquot;, quot;Nedquot;]
      }                                  3
      out.println(shortNames.size()); Ted
      for(String s : shortNames) {       Jed
        out.println(s);                  Ned
      }
   }
} Spring Framework Meeting, 14 June 2008
10
              Groovy Closures – Step 2 ListTests.groovy

        class ListTests {
          static void main(String... args) {
            List<String> names = ['Ted', 'Fred', 'Jed', 'Ned']
            println quot;${names.class} ${names}quot;
            List<String> shortNames = new ArrayList()
            for(String s : names) {
              if (s.length() < 4) {
                shortNames << s
              }
            }
            println shortNames.size()
            shortNames.each { println it }
          }
        }




Spring Framework Meeting, 14 June 2008
11
              Groovy Closures – Step 3 ListTests.groovy

        List<String> names = ['Ted', 'Fred', 'Jed', 'Ned']
        println quot;${names.class} ${names}quot;
        List<String> shortNames = names.findAll { it.length() < 4 }
        println shortNames.size()
        shortNames.each { println it }
          JUGSardegna>groovy ListTests.groovy
          class java.util.ArrayList [quot;Tedquot;, quot;Fredquot;, quot;Jedquot;, quot;Nedquot;]
          3
          Ted
          Jed
          Ned
                            Idiomatic Groovy
                                Reduced clutter
                                Simple concise syntax
  Adapted from: http://groovy.dzone.com/news/java-groovy-part-2-closures-an


Spring Framework Meeting, 14 June 2008
12
              Meta Object Protocol - MOP

         Introspection:
            MyClass.metaClass.methods.each { println it.name }
            MyClass.metaClass.properties.each { println it.name }
            MyClass.metaClass.respondsTo(obj, 'execute')
            MyClass.metaClass.hasProperty(obj, 'status')

         Dynamic method invocation:
            obj.quot;$namequot;()

         Dynamic property getters and setters:
            Object value = obj.quot;$namequot;
            obj.quot;$namequot; = value



Spring Framework Meeting, 14 June 2008
13
              Meta Object Protocol - MOP


Intercepting (Aspect Oriented Programming)
  def invokeMethod = { String name, args -> println quot;$name invokedquot; }
  def getProperty = { String name -> println quot;getting $namequot; }
  def setProperty = { String name, value -> println quot;setting $namequot; }

Changing behaviour at run time:
  def methodMissing = { String name, args -> quot;No $name methodquot; }
  def propertyMissing = { String name -> quot;No $name propertyquot; }
  Duck.metaClass.quack = { quot;Quack!quot; } // duck.quack()
  Duck.metaClass.getSpecies = { -> quot;Canardquot; } // duck.species




Spring Framework Meeting, 14 June 2008
14
              Domain Specific Language: AntBuilder

 AntBuilder ant = new AntBuilder()
 String myDir = 'target/AntTest/'
 ant.sequential {
   echo('inside sequential')
   mkdir(dir: myDir)
   copy(todir: myDir) {
     fileset(dir: 'src/test') {
       include(name: '**/*.groovy')
     }
   }
   echo('done')
 }
 File file = new File('target/AntTest/groovy/util/AntTest.groovy')
 assert file.exists() // yes it does
         Adapted from:   http://groovy.codehaus.org/Using+Ant+from+Groovy

     Gant – Groovy, Ant, but no XML: http://gant.codehaus.org/

Spring Framework Meeting, 14 June 2008
15
              Domain Specific Language: MarkupBuilder

    Groovy snippet:
    MarkupBuilder xml = new MarkupBuilder(writer)
    xml.'rec:records'('xmlns:rec':'http://groovy.codehaus.org') {
      car(name:'HSV Maloo', make:'Holden', year:2006) {
        country('Australia')
        record(type:'speed', ' Truck with speed of 271kph')
      }
    }

    Output snippet:
    <rec:records xmlns:rec='http://groovy.codehaus.org'>
      <car name='HSV Maloo' make='Holden' year='2006'>
        <country>Australia</country>
        <record type='speed'> Truck with speed of 271kph</record>
      </car>
    </rec:records>
  Adapted from: http://groovy.codehaus.org/Creating+XML+using+Groovy's+MarkupBuilder


Spring Framework Meeting, 14 June 2008
16
              But Wait, there's More!

Ranges – 0..9, 0.<10
Curried closures
Regular expression syntax sugar - /d+/
Extended switch operator – switch(title) { case 'Groovy': ...
Operator overloading – list << item
Elvis operator – value = value ?: defaultValue;
Safe dereferencing - person?.parents?.grandParents
The Expando class – saves writing a 'real' class
Unit testing, the Groovy Mock Library
SwingBuilder
Joint compiler (compile Groovy and Java source code together)
...
But we don't have time for all that now

Spring Framework Meeting, 14 June 2008
17
              Groovy – the Good News

Past the version 1.0 barrier (2 Jan 2007)

IDE support is maturing (Eclipse, NetBeans, and IntelliJ IDEA)

Being used in industry

Currently around 30th place according to TIOBE (http://www.tiobe.com)

G2One Inc., support from the Lead developer (Guillaume Laforge)

IBM Project Zero

“Drill down” to Java when you need the speed


Spring Framework Meeting, 14 June 2008
18
              Groovy – the Bad News




                  IDE support is still maturing

                  Slow execution speed (but not s-l-o-w)

                  Idiomatic Groovy is not Java

                  Won't get you a Job




Spring Framework Meeting, 14 June 2008
19
              Groovy – the Fear, Uncertainty, and Doubt



          Interpreted language – no, compiled to Java bytecode

          Not a standard – no, JSR 241

          Orphan project – no Sun, Oracle, IBM, IntelliJ support

          Usurping Java – no, augmenting Java

          No Groovy programmers – no, most Java programmers
             should understand it




Spring Framework Meeting, 14 June 2008
20
              Pragmatic Groovy



          Start in places where execution speed is less important:

              Build scripts – AntBuilder, Gant

              Unit testing, and mocking

              Swing User Interfaces – SwingBuilder

              Domain Specific Languages




Spring Framework Meeting, 14 June 2008
21
              Grails – What's in the Box?


                    Generators
                    Predefined application layout (folders)
                    Model View Controller pattern - surprise!
                    GORM – Hibernate made easy
                    Spring and Spring MVC under the covers
                    SiteMesh powering the views
                    Groovy Server Pages (GSP)
                    Tag Libraries but no XML
                    Plug-in architecture
                    Testing – unit, integration, web
                    Excellent, concise documentation



Spring Framework Meeting, 14 June 2008
22
               Generators

         grails create-app        Creates (and populates) the application directories
grails create-domain-class        Creates an empty domain (model) class
     grails create-service        Creates a transactional business logic class
     grails create-tag-lib        Creates an empty tag library class
   grails create-unit-test        Creates a unit test class
grails generate-controller        Generates a CRUD controller class for a domain class
     grails generate-views        Generates the four CRUD views for a domain class
            grails run-app        Runs the web application in Jetty
           grails test-app        Runs the unit tests
            grails console        Runs the Grails Swing interactive console
              grails shell        Runs the Grails interactive shell
                grails war        Creates a war file for JEE deployment
             Run grails create-app, then grails run-app,
 and you've got an (empty) running web application, in less than 30 seconds
                   You'll still have to write some code yourself

 Spring Framework Meeting, 14 June 2008
23
                Domain Models
class Album {                              class Picture {
  User user                                   User user
  String caption                              Album album
  String description                   POGO   Set images
  Set pictures                                String file
                                              String caption

                                 Associations
  static belongsTo = User                     static belongsTo = [ User, Album ]
  static hasMany = [ pictures:Picture ]       static hasMany = [ images:Image ]


  static constraints = {
                           Validation         Transient properties
    caption(size:1..40, blank:false)          static transients = [ 'file' ]
  }

                       Object Relational Mapping
  static mapping = {                      static mapping = {
    pictures cascade:'all', inverse:true    images cascade:'all', inverse:true
    description type:'text'               }
    user index:'user_idx', unique:false }
  }
} Spring Framework Meeting, 14 June 2008
24
              Views

                                            views/layouts/main.gsp
     <!DOCTYPE html ... >
     <html xmlns=quot;http://www.w3.org/1999/xhtmlquot;>
       <head>
         <title><g:layoutTitle default=quot;WebAlbumquot; /></title>
         <link rel=quot;stylesheetquot; type=quot;text/cssquot;
           href=quot;${createLinkTo(dir:'css', file:'main.css')}quot;/>
         <g:layoutHead />
       </head>
       <body>
         <div class='title'>WebAlbum</div>
         <div class='content'>
           <g:layoutBody />
         </div>
       </body>
     </html>



Spring Framework Meeting, 14 June 2008
25
            Views
<html>
  <head>
     <meta name=quot;layoutquot; content=quot;mainquot; /> views/picture/create.gsp
     <title>WebAlbum : Create Picture</title>           <g:layoutTitle />
     <script type=quot;text/javascriptquot;> ... </script>
  </head>                                               <g:layoutHead />
  <body>
     <h1>Create Picture</h1>                            <g:layoutBody />
        <g:uploadForm action=quot;savequot;>
              ...
           <td valign=quot;topquot; class=quot;namequot;>
             <label for=quot;captionquot;>Caption:</label>
           </td>
           <td valign=quot;topquot; class=quot;valuequot;>
             <input type=quot;textquot; size=quot;40quot; maxlength=quot;40quot;
               id=quot;captionquot; name=quot;captionquot;
               value=quot;${fieldValue(bean: picture, field: 'caption')}quot;/>
           </td>
              ...
        </g:uploadForm>                          domain/Picture.groovy
  </body>
</html>
 Spring Framework Meeting, 14 June 2008
26
              Controllers

class PictureController {

    def list = {
      [list:Picture.list(params), paginateCount:Picture.count()]
    }

    def show = {
      Picture picture = Picture.get(params.id)
      if (!picture) {
        flash.message = quot;Picture not foundquot;
        redirect(action:list)
      }
      else {
        return [picture:picture]
      }
    }
    ...
}

Spring Framework Meeting, 14 June 2008
27
              Controllers

class PictureController {

    def beforeInterceptor = [ action:this.&intercept, only:['create']]

    def create = {
      ...
    }

    def intercept() {
      User user = sessionUser()
      if (!user || user.albumsCount == 0) {
        flash.warning = quot;You must create an album first!quot;
        redirect(controller: 'album', action: 'create')
        return false
      }
      true
    }
}

Spring Framework Meeting, 14 June 2008
28
              Tag Libraries

                                           views/picture/show.gsp


...
<tr class=quot;propquot;>
  <td valign=quot;topquot; class=quot;namequot;>Caption:</td>
  <td valign=quot;topquot; class=quot;valuequot;>
    <wa:pictureAnchor picture=quot;${picture}quot; size=quot;${Image.Original}quot;>
      ${picture.caption ?: '...'}
    </wa:pictureAnchor>
  </td>
</tr>
...




Spring Framework Meeting, 14 June 2008
29
              Tag Libraries

class WebAlbumTagLib {                   taglib/WebAlbumTagLib.groovy
    static namespace = quot;waquot;

    def pictureAnchor = { attrs, body ->
      Picture picture = attrs.remove('picture')
      def size = attrs.remove('size')
      String link = createPictureLink(picture.id, size).encodeAsHTML()
      out << quot;<a href=quot;${link}quot;quot;
      attrs.each { key, value ->
        out << quot; $key=quot;$valuequot;quot;
      }
      out << '>'
      out << body()
      out << '</a>'
    }
    ...
}

Spring Framework Meeting, 14 June 2008
30
              But Wait, there's More!

Filters – conf/WebAlbumFilter.groovy
Create Gant scripts – scripts/CompileSources.groovy
GORM many-to-many, composition, inheritance, eager fetching, ...
GORM dynamic finders – findByFirstNameAndLastName(...)
GORM transactions – User.withTransaction { status -> ... }
Controller chaining
Shared templates
URL mappings - quot;/salequot;(controller:'product', action:'sale')
Multiple request conversations – Web Flow
Ajax support – Prototype, Dojo, Yahoo UI, GWT
Content negotiation
Web Services – REST and SOAP
...
But we don't have time for all that now

Spring Framework Meeting, 14 June 2008
31
              Grails – the Good News



    Past the version 1.0 barrier (4 Feb 2008)

    IDE support is maturing (Eclipse, NetBeans, and IntelliJ IDEA)

    Being used in industry

    G2One Inc., support from the Lead developer (Graeme Rocher)

    “Drill down” to Java when you need to




Spring Framework Meeting, 14 June 2008
32
              Grails – the Bad News




                   IDE support is still maturing

                   Slow execution speed (but not s-l-o-w)

                   Won't get you a Job




Spring Framework Meeting, 14 June 2008
33
               Grails – the Fear, Uncertainty, and Doubt


 Another Rails clone – no, uses the philosophy in a Groovy/Java way

 Built with an interpreted language (Groovy) – no, 20% Groovy which
    compiles to bytecode anyway

 No Grails programmers – no, see no Groovy programmers

 Only good for CRUD applications – no, you can do any full stack JEE
    application, SOAP and REST included

 Much slower than JEE – no, Sun engineers results showed JEE
   to be 2 to 4 times faster with 100 to 500 concurrent users
     http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-9535&yr=2007&track=9




Spring Framework Meeting, 14 June 2008
34
              Pragmatic Grails



          Start in places where execution speed is less important:

              In-house web applications

              “Long tail” applications (10 – 50 concurrent users)

              Prototyping a JEE web application




Spring Framework Meeting, 14 June 2008
35
              What's Next?



 Groovy: http://groovy.codehaus.org/
 Grails: http://grails.org/
 About Groovy: http://aboutgroovy.com/
 Groovy Zone: http://groovy.dzone.com/
 InfoQ Groovy: http://www.infoq.com/groovy
 InfoQ Grails: http://www.infoq.com/grails
 Graeme Rocher's blog: http://graemerocher.blogspot.com/
 Guillaume Laforge's blog: http://glaforge.free.fr/weblog/
 G2One Inc.: http://www.g2one.com/index.html




Spring Framework Meeting, 14 June 2008
36
              Read the Books, Watch the Movies



   Books:
     Groovy Recipes: http://pragprog.com/titles/sdgrvr
     Programming Groovy: http://pragprog.com/titles/vslg
     Groovy in Action: http://www.manning.com/koenig/
     The Definitive Guide to Grails:
         http://www.apress.com/book/view/1590597583

   Films:
       Grails eXchange 2007: http://grails-exchange.com/




Spring Framework Meeting, 14 June 2008
37
              Thank You, any Questions?


                 Syger: http://www.syger.it/

Grails WebAlbum:
  http://www.syger.it/Tutorials/GrailsWebAlbum.html

Ruby on Rails WebAlbum (a comparison, written first):
  http://www.syger.it/Tutorials/RubyOnRailsWebAlbum.html

            My personal site: http://www.jhl.it/

                 Contact: john.leach@syger.it



Spring Framework Meeting, 14 June 2008

More Related Content

What's hot

Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 WinterHuahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 WinterRyu Kobayashi
 
Vaadin7 modern-web-apps-in-java
Vaadin7 modern-web-apps-in-javaVaadin7 modern-web-apps-in-java
Vaadin7 modern-web-apps-in-javaJoonas Lehtinen
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Anton Arhipov
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Artur Latoszewski
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistAnton Arhipov
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRCtepsum
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩GDG Korea
 
Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113SOAT
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentSchalk Cronjé
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsMarcin Grzejszczak
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyIván López Martín
 

What's hot (20)

Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Vaadin 7
Vaadin 7Vaadin 7
Vaadin 7
 
Vaadin 7
Vaadin 7Vaadin 7
Vaadin 7
 
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 WinterHuahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
 
Vaadin7 modern-web-apps-in-java
Vaadin7 modern-web-apps-in-javaVaadin7 modern-web-apps-in-java
Vaadin7 modern-web-apps-in-java
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011
 
京都Gtugコンパチapi
京都Gtugコンパチapi京都Gtugコンパチapi
京都Gtugコンパチapi
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 
Brubeck: Overview
Brubeck: OverviewBrubeck: Overview
Brubeck: Overview
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩
 
hibernate
hibernatehibernate
hibernate
 
Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM Development
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovy
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 

Viewers also liked

Ideas for Developing Financial Resources
Ideas for Developing Financial ResourcesIdeas for Developing Financial Resources
Ideas for Developing Financial ResourcesNew World Foundation
 
Social Media for Small Businesses
Social Media for Small BusinessesSocial Media for Small Businesses
Social Media for Small BusinessesJaki Levy
 
Backup e restore - rdiff backup
Backup e restore - rdiff backupBackup e restore - rdiff backup
Backup e restore - rdiff backupJohn Leach
 
Soundstreams Presentation by Jaki Levy
Soundstreams Presentation by Jaki LevySoundstreams Presentation by Jaki Levy
Soundstreams Presentation by Jaki LevyJaki Levy
 
Socially Networked Arts Groups
Socially Networked Arts GroupsSocially Networked Arts Groups
Socially Networked Arts GroupsJaki Levy
 
Passover 2011
Passover 2011Passover 2011
Passover 2011Jaki Levy
 
Ideas for Developing Financial Resources
Ideas for Developing Financial ResourcesIdeas for Developing Financial Resources
Ideas for Developing Financial ResourcesNew World Foundation
 
Soundstreams Presentation by Jaki Levy
Soundstreams Presentation by Jaki LevySoundstreams Presentation by Jaki Levy
Soundstreams Presentation by Jaki LevyJaki Levy
 

Viewers also liked (12)

Ideas for Developing Financial Resources
Ideas for Developing Financial ResourcesIdeas for Developing Financial Resources
Ideas for Developing Financial Resources
 
Social Media for Small Businesses
Social Media for Small BusinessesSocial Media for Small Businesses
Social Media for Small Businesses
 
Backup e restore - rdiff backup
Backup e restore - rdiff backupBackup e restore - rdiff backup
Backup e restore - rdiff backup
 
Report: Funding Social Movements
Report: Funding Social MovementsReport: Funding Social Movements
Report: Funding Social Movements
 
Soundstreams Presentation by Jaki Levy
Soundstreams Presentation by Jaki LevySoundstreams Presentation by Jaki Levy
Soundstreams Presentation by Jaki Levy
 
Socially Networked Arts Groups
Socially Networked Arts GroupsSocially Networked Arts Groups
Socially Networked Arts Groups
 
Passover 2011
Passover 2011Passover 2011
Passover 2011
 
Ideas for Developing Financial Resources
Ideas for Developing Financial ResourcesIdeas for Developing Financial Resources
Ideas for Developing Financial Resources
 
Funding Social Movements
Funding Social MovementsFunding Social Movements
Funding Social Movements
 
Funding Social Movements
Funding Social MovementsFunding Social Movements
Funding Social Movements
 
Building a New Majority (2005)
Building a New Majority (2005)Building a New Majority (2005)
Building a New Majority (2005)
 
Soundstreams Presentation by Jaki Levy
Soundstreams Presentation by Jaki LevySoundstreams Presentation by Jaki Levy
Soundstreams Presentation by Jaki Levy
 

Similar to Groovy And Grails JUG Sardegna

Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovymanishkp84
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemKostas Saidis
 
Introduction to Oracle Groovy
Introduction to Oracle GroovyIntroduction to Oracle Groovy
Introduction to Oracle GroovyDeepak Bhagat
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyAndres Almiray
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java DevelopersAndres Almiray
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyJames Williams
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingAndres Almiray
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsIndicThreads
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applicationsrohitnayak
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGuillaume Laforge
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyAndres Almiray
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、GaelykでハンズオンTsuyoshi Yamamoto
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with GroovyAli Tanwir
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for JavaCharles Anderson
 

Similar to Groovy And Grails JUG Sardegna (20)

Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
 
Introduction to Oracle Groovy
Introduction to Oracle GroovyIntroduction to Oracle Groovy
Introduction to Oracle Groovy
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java Developers
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applications
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
MetaProgramming with Groovy
MetaProgramming with GroovyMetaProgramming with Groovy
MetaProgramming with Groovy
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for Java
 
OpenLogic
OpenLogicOpenLogic
OpenLogic
 
Svcc Groovy Testing
Svcc Groovy TestingSvcc Groovy Testing
Svcc Groovy Testing
 

Recently uploaded

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Groovy And Grails JUG Sardegna

  • 1. 1 Groovy and Grails What are they, and what are the benefits and risks? Spring Framework Meeting, 14 June 2008
  • 2. 2 Who am I? John Leach, Chief Technical Officer for Syger Java developer from the start – and still learning Syger - a small software consultancy in Verona, Italy Who are you? Who's heard of Groovy? Who's heard of Grails? Who writes web applications? Pleased to meet you Warning! Intensive content session Lots to see, not much time Questions at the end Spring Framework Meeting, 14 June 2008
  • 3. 3 Overview of Dynamic scripting language Similar syntax to Java Evolution not revolution But... with closures and meta programming and relaxed typing and lots of syntax sugar and a silly name - sigh Spring Framework Meeting, 14 June 2008
  • 4. 4 Overview of Ruby on Rails philosophy – evolution not revolution Convention over configuration Uses 20% Groovy and 80% Java (elegance and power) But... with Spring, Hibernate, and SiteMesh has a plugin architecture no XML (though it's there when you need it) no HQL/SQL (though they're there when you need them) no Ruby, JRuby or Rails Spring Framework Meeting, 14 June 2008
  • 5. 5 Java to Groovy – Step 1 HelloWorld.groovy public class HelloWorld { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return quot;Hello quot; + name; } public static void main(String... args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(quot;Groovyquot;); System.out.println(helloWorld.greet()); } } Spring Framework Meeting, 14 June 2008
  • 6. 6 Java to Groovy – Step 2 HelloWorld.groovy class HelloWorld { String name String greet() { return quot;Hello quot; + name } static void main(String... args) { HelloWorld helloWorld = new HelloWorld() helloWorld.name = 'Groovy' println(helloWorld.greet()) } } Spring Framework Meeting, 14 June 2008
  • 7. 7 Java to Groovy – Step 3 HelloWorld.groovy class HelloWorld { String name String greet() { quot;Hello ${name}quot; } static void main(String... args) { println new HelloWorld(name: 'Groovy').greet() } } Plain Ordinary Groovy Objects Reduced clutter Simple constructors Adapted from: http://groovy.dzone.com/news/java-groovy-few-easy-steps Spring Framework Meeting, 14 June 2008
  • 8. 8 Java to Groovy – Check HelloWorld.class Groovy: JUGSardegna>groovy HelloWorld.groovy Hello Groovy Java: JUGSardegna>groovyc HelloWorld.groovy JUGSardegna>java -cp %GROOVY_HOME%embeddablegroovy-all-1.5.4.jar;. HelloWorld Hello Groovy Javap: JUGSardegna>javap HelloWorld Compiled from quot;HelloWorld.groovyquot; public class HelloWorld extends java.lang.Object implements groovy.lang.GroovyObject { public HelloWorld(); public java.lang.String greet(); public java.lang.String getName(); public void setName(java.lang.String); public static java.lang.Object main(java.lang.String[]); ... } Spring Framework Meeting, 14 June 2008
  • 9. 9 Groovy Closures – Step 1 ListTests.groovy import static java.lang.System.out; import static java.util.Arrays.asList; import java.util.ArrayList; import java.util.List; public class ListTests { public static void main(String... args) { List<String> names = asList(quot;Tedquot;, quot;Fredquot;, quot;Jedquot;, quot;Nedquot;); out.println(names.getClass().toString() + quot; quot; + names); List<String> shortNames = new ArrayList<String>(); for(String s : names) { if (s.length() < 4) { JUGSardegna>groovy ListTests.groovy shortNames.add(s); class java.util.Arrays$ArrayList } [quot;Tedquot;, quot;Fredquot;, quot;Jedquot;, quot;Nedquot;] } 3 out.println(shortNames.size()); Ted for(String s : shortNames) { Jed out.println(s); Ned } } } Spring Framework Meeting, 14 June 2008
  • 10. 10 Groovy Closures – Step 2 ListTests.groovy class ListTests { static void main(String... args) { List<String> names = ['Ted', 'Fred', 'Jed', 'Ned'] println quot;${names.class} ${names}quot; List<String> shortNames = new ArrayList() for(String s : names) { if (s.length() < 4) { shortNames << s } } println shortNames.size() shortNames.each { println it } } } Spring Framework Meeting, 14 June 2008
  • 11. 11 Groovy Closures – Step 3 ListTests.groovy List<String> names = ['Ted', 'Fred', 'Jed', 'Ned'] println quot;${names.class} ${names}quot; List<String> shortNames = names.findAll { it.length() < 4 } println shortNames.size() shortNames.each { println it } JUGSardegna>groovy ListTests.groovy class java.util.ArrayList [quot;Tedquot;, quot;Fredquot;, quot;Jedquot;, quot;Nedquot;] 3 Ted Jed Ned Idiomatic Groovy Reduced clutter Simple concise syntax Adapted from: http://groovy.dzone.com/news/java-groovy-part-2-closures-an Spring Framework Meeting, 14 June 2008
  • 12. 12 Meta Object Protocol - MOP Introspection: MyClass.metaClass.methods.each { println it.name } MyClass.metaClass.properties.each { println it.name } MyClass.metaClass.respondsTo(obj, 'execute') MyClass.metaClass.hasProperty(obj, 'status') Dynamic method invocation: obj.quot;$namequot;() Dynamic property getters and setters: Object value = obj.quot;$namequot; obj.quot;$namequot; = value Spring Framework Meeting, 14 June 2008
  • 13. 13 Meta Object Protocol - MOP Intercepting (Aspect Oriented Programming) def invokeMethod = { String name, args -> println quot;$name invokedquot; } def getProperty = { String name -> println quot;getting $namequot; } def setProperty = { String name, value -> println quot;setting $namequot; } Changing behaviour at run time: def methodMissing = { String name, args -> quot;No $name methodquot; } def propertyMissing = { String name -> quot;No $name propertyquot; } Duck.metaClass.quack = { quot;Quack!quot; } // duck.quack() Duck.metaClass.getSpecies = { -> quot;Canardquot; } // duck.species Spring Framework Meeting, 14 June 2008
  • 14. 14 Domain Specific Language: AntBuilder AntBuilder ant = new AntBuilder() String myDir = 'target/AntTest/' ant.sequential { echo('inside sequential') mkdir(dir: myDir) copy(todir: myDir) { fileset(dir: 'src/test') { include(name: '**/*.groovy') } } echo('done') } File file = new File('target/AntTest/groovy/util/AntTest.groovy') assert file.exists() // yes it does Adapted from: http://groovy.codehaus.org/Using+Ant+from+Groovy Gant – Groovy, Ant, but no XML: http://gant.codehaus.org/ Spring Framework Meeting, 14 June 2008
  • 15. 15 Domain Specific Language: MarkupBuilder Groovy snippet: MarkupBuilder xml = new MarkupBuilder(writer) xml.'rec:records'('xmlns:rec':'http://groovy.codehaus.org') { car(name:'HSV Maloo', make:'Holden', year:2006) { country('Australia') record(type:'speed', ' Truck with speed of 271kph') } } Output snippet: <rec:records xmlns:rec='http://groovy.codehaus.org'> <car name='HSV Maloo' make='Holden' year='2006'> <country>Australia</country> <record type='speed'> Truck with speed of 271kph</record> </car> </rec:records> Adapted from: http://groovy.codehaus.org/Creating+XML+using+Groovy's+MarkupBuilder Spring Framework Meeting, 14 June 2008
  • 16. 16 But Wait, there's More! Ranges – 0..9, 0.<10 Curried closures Regular expression syntax sugar - /d+/ Extended switch operator – switch(title) { case 'Groovy': ... Operator overloading – list << item Elvis operator – value = value ?: defaultValue; Safe dereferencing - person?.parents?.grandParents The Expando class – saves writing a 'real' class Unit testing, the Groovy Mock Library SwingBuilder Joint compiler (compile Groovy and Java source code together) ... But we don't have time for all that now Spring Framework Meeting, 14 June 2008
  • 17. 17 Groovy – the Good News Past the version 1.0 barrier (2 Jan 2007) IDE support is maturing (Eclipse, NetBeans, and IntelliJ IDEA) Being used in industry Currently around 30th place according to TIOBE (http://www.tiobe.com) G2One Inc., support from the Lead developer (Guillaume Laforge) IBM Project Zero “Drill down” to Java when you need the speed Spring Framework Meeting, 14 June 2008
  • 18. 18 Groovy – the Bad News IDE support is still maturing Slow execution speed (but not s-l-o-w) Idiomatic Groovy is not Java Won't get you a Job Spring Framework Meeting, 14 June 2008
  • 19. 19 Groovy – the Fear, Uncertainty, and Doubt Interpreted language – no, compiled to Java bytecode Not a standard – no, JSR 241 Orphan project – no Sun, Oracle, IBM, IntelliJ support Usurping Java – no, augmenting Java No Groovy programmers – no, most Java programmers should understand it Spring Framework Meeting, 14 June 2008
  • 20. 20 Pragmatic Groovy Start in places where execution speed is less important: Build scripts – AntBuilder, Gant Unit testing, and mocking Swing User Interfaces – SwingBuilder Domain Specific Languages Spring Framework Meeting, 14 June 2008
  • 21. 21 Grails – What's in the Box? Generators Predefined application layout (folders) Model View Controller pattern - surprise! GORM – Hibernate made easy Spring and Spring MVC under the covers SiteMesh powering the views Groovy Server Pages (GSP) Tag Libraries but no XML Plug-in architecture Testing – unit, integration, web Excellent, concise documentation Spring Framework Meeting, 14 June 2008
  • 22. 22 Generators grails create-app Creates (and populates) the application directories grails create-domain-class Creates an empty domain (model) class grails create-service Creates a transactional business logic class grails create-tag-lib Creates an empty tag library class grails create-unit-test Creates a unit test class grails generate-controller Generates a CRUD controller class for a domain class grails generate-views Generates the four CRUD views for a domain class grails run-app Runs the web application in Jetty grails test-app Runs the unit tests grails console Runs the Grails Swing interactive console grails shell Runs the Grails interactive shell grails war Creates a war file for JEE deployment Run grails create-app, then grails run-app, and you've got an (empty) running web application, in less than 30 seconds You'll still have to write some code yourself Spring Framework Meeting, 14 June 2008
  • 23. 23 Domain Models class Album { class Picture { User user User user String caption Album album String description POGO Set images Set pictures String file String caption Associations static belongsTo = User static belongsTo = [ User, Album ] static hasMany = [ pictures:Picture ] static hasMany = [ images:Image ] static constraints = { Validation Transient properties caption(size:1..40, blank:false) static transients = [ 'file' ] } Object Relational Mapping static mapping = { static mapping = { pictures cascade:'all', inverse:true images cascade:'all', inverse:true description type:'text' } user index:'user_idx', unique:false } } } Spring Framework Meeting, 14 June 2008
  • 24. 24 Views views/layouts/main.gsp <!DOCTYPE html ... > <html xmlns=quot;http://www.w3.org/1999/xhtmlquot;> <head> <title><g:layoutTitle default=quot;WebAlbumquot; /></title> <link rel=quot;stylesheetquot; type=quot;text/cssquot; href=quot;${createLinkTo(dir:'css', file:'main.css')}quot;/> <g:layoutHead /> </head> <body> <div class='title'>WebAlbum</div> <div class='content'> <g:layoutBody /> </div> </body> </html> Spring Framework Meeting, 14 June 2008
  • 25. 25 Views <html> <head> <meta name=quot;layoutquot; content=quot;mainquot; /> views/picture/create.gsp <title>WebAlbum : Create Picture</title> <g:layoutTitle /> <script type=quot;text/javascriptquot;> ... </script> </head> <g:layoutHead /> <body> <h1>Create Picture</h1> <g:layoutBody /> <g:uploadForm action=quot;savequot;> ... <td valign=quot;topquot; class=quot;namequot;> <label for=quot;captionquot;>Caption:</label> </td> <td valign=quot;topquot; class=quot;valuequot;> <input type=quot;textquot; size=quot;40quot; maxlength=quot;40quot; id=quot;captionquot; name=quot;captionquot; value=quot;${fieldValue(bean: picture, field: 'caption')}quot;/> </td> ... </g:uploadForm> domain/Picture.groovy </body> </html> Spring Framework Meeting, 14 June 2008
  • 26. 26 Controllers class PictureController { def list = { [list:Picture.list(params), paginateCount:Picture.count()] } def show = { Picture picture = Picture.get(params.id) if (!picture) { flash.message = quot;Picture not foundquot; redirect(action:list) } else { return [picture:picture] } } ... } Spring Framework Meeting, 14 June 2008
  • 27. 27 Controllers class PictureController { def beforeInterceptor = [ action:this.&intercept, only:['create']] def create = { ... } def intercept() { User user = sessionUser() if (!user || user.albumsCount == 0) { flash.warning = quot;You must create an album first!quot; redirect(controller: 'album', action: 'create') return false } true } } Spring Framework Meeting, 14 June 2008
  • 28. 28 Tag Libraries views/picture/show.gsp ... <tr class=quot;propquot;> <td valign=quot;topquot; class=quot;namequot;>Caption:</td> <td valign=quot;topquot; class=quot;valuequot;> <wa:pictureAnchor picture=quot;${picture}quot; size=quot;${Image.Original}quot;> ${picture.caption ?: '...'} </wa:pictureAnchor> </td> </tr> ... Spring Framework Meeting, 14 June 2008
  • 29. 29 Tag Libraries class WebAlbumTagLib { taglib/WebAlbumTagLib.groovy static namespace = quot;waquot; def pictureAnchor = { attrs, body -> Picture picture = attrs.remove('picture') def size = attrs.remove('size') String link = createPictureLink(picture.id, size).encodeAsHTML() out << quot;<a href=quot;${link}quot;quot; attrs.each { key, value -> out << quot; $key=quot;$valuequot;quot; } out << '>' out << body() out << '</a>' } ... } Spring Framework Meeting, 14 June 2008
  • 30. 30 But Wait, there's More! Filters – conf/WebAlbumFilter.groovy Create Gant scripts – scripts/CompileSources.groovy GORM many-to-many, composition, inheritance, eager fetching, ... GORM dynamic finders – findByFirstNameAndLastName(...) GORM transactions – User.withTransaction { status -> ... } Controller chaining Shared templates URL mappings - quot;/salequot;(controller:'product', action:'sale') Multiple request conversations – Web Flow Ajax support – Prototype, Dojo, Yahoo UI, GWT Content negotiation Web Services – REST and SOAP ... But we don't have time for all that now Spring Framework Meeting, 14 June 2008
  • 31. 31 Grails – the Good News Past the version 1.0 barrier (4 Feb 2008) IDE support is maturing (Eclipse, NetBeans, and IntelliJ IDEA) Being used in industry G2One Inc., support from the Lead developer (Graeme Rocher) “Drill down” to Java when you need to Spring Framework Meeting, 14 June 2008
  • 32. 32 Grails – the Bad News IDE support is still maturing Slow execution speed (but not s-l-o-w) Won't get you a Job Spring Framework Meeting, 14 June 2008
  • 33. 33 Grails – the Fear, Uncertainty, and Doubt Another Rails clone – no, uses the philosophy in a Groovy/Java way Built with an interpreted language (Groovy) – no, 20% Groovy which compiles to bytecode anyway No Grails programmers – no, see no Groovy programmers Only good for CRUD applications – no, you can do any full stack JEE application, SOAP and REST included Much slower than JEE – no, Sun engineers results showed JEE to be 2 to 4 times faster with 100 to 500 concurrent users http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-9535&yr=2007&track=9 Spring Framework Meeting, 14 June 2008
  • 34. 34 Pragmatic Grails Start in places where execution speed is less important: In-house web applications “Long tail” applications (10 – 50 concurrent users) Prototyping a JEE web application Spring Framework Meeting, 14 June 2008
  • 35. 35 What's Next? Groovy: http://groovy.codehaus.org/ Grails: http://grails.org/ About Groovy: http://aboutgroovy.com/ Groovy Zone: http://groovy.dzone.com/ InfoQ Groovy: http://www.infoq.com/groovy InfoQ Grails: http://www.infoq.com/grails Graeme Rocher's blog: http://graemerocher.blogspot.com/ Guillaume Laforge's blog: http://glaforge.free.fr/weblog/ G2One Inc.: http://www.g2one.com/index.html Spring Framework Meeting, 14 June 2008
  • 36. 36 Read the Books, Watch the Movies Books: Groovy Recipes: http://pragprog.com/titles/sdgrvr Programming Groovy: http://pragprog.com/titles/vslg Groovy in Action: http://www.manning.com/koenig/ The Definitive Guide to Grails: http://www.apress.com/book/view/1590597583 Films: Grails eXchange 2007: http://grails-exchange.com/ Spring Framework Meeting, 14 June 2008
  • 37. 37 Thank You, any Questions? Syger: http://www.syger.it/ Grails WebAlbum: http://www.syger.it/Tutorials/GrailsWebAlbum.html Ruby on Rails WebAlbum (a comparison, written first): http://www.syger.it/Tutorials/RubyOnRailsWebAlbum.html My personal site: http://www.jhl.it/ Contact: john.leach@syger.it Spring Framework Meeting, 14 June 2008