SlideShare a Scribd company logo
1 of 39
Download to read offline
AMIS – 26 november 2012
INTRODUCTIE IN GROOVY
OVER JAVA

                • Academisch
                   • Uitgewerkt concept,      Super uitgespecificeerd
                • Bewezen
                   • Performant,     Platform onafhankelijk
                   • Robust,         Secure (?)
                • Antiek
                   • Modern in 1995
                   • Vergelijk: C#, Python, Ruby, JavaScript, Smalltalk, Go
                • Autistisch
private String name;

public void setName(String name) {
    this.name = name;
}
                              import   java.io.*;
                              import   java.math.BigDecimal;
public String getName() {
                              import   java.net.*;
    return name;
                              import   java.util.*;
}
OVER JAVA – VERGELIJKING

Java                                           C#
public class Pet {                             public class Pet
    private PetName name;                      {
    private Person owner;                        public PetName Name { get; set; }
                                                 public Person Owner { get; set; }
    public Pet(PetName name, Person owner) {   }
        this.name = name;
        this.owner = owner;
    }

    public PetName getName() {
        return name;
    }

    public void setName(PetName name) {
        this.name = name;
    }

    public Person getOwner() {
        return owner;
    }

    public void setOwner(Person owner) {
        this.owner = owner;
    }
}
OVER JAVA – VERGELIJKING

Java                                  Python
Map<String, Integer> map =            map = {'een':1, 'twee':2, 'drie':3,
    new HashMap<String, Integer>();    'vier':4, 'vijf':5, 'zes':6}
map.put("een", 1);
map.put("twee", 2);
map.put("drie", 3);
map.put("vier", 4);
map.put("vijf", 5);
map.put("zes", 6);
OVER JAVA – VERGELIJKING

Java                                           Python
FileInputStream fis = null;                    with open('file.txt', 'r') as f:
InputStreamReader isr = null;                       for line in f:
BufferedReader br = null;                                 print line,
try {
    fis = new FileInputStream("file.txt");
    isr = new InputStreamReader(fis);
    br = new BufferedReader(isr);
    String line;
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
} catch (IOException e) {
    throw new RuntimeException(e);
} finally {
    if (br != null)
        try { br.close();
        } catch (IOException e) { }
    if (isr != null)
        try { isr.close();
        } catch (IOException e) { }
    if (fis != null)
        try { fis.close();
        } catch (IOException e) { }
}
OVER GROOVY

• Sinds:    2003
• Door:     James Strachan
• Target:   Java ontwikkelaars

• Basis:    Java
• Plus:     “Al het goede” van Ruby, Python en Smalltalk

• Apache Licence
• Uitgebreide community
• Ondersteund door SpringSource (VMWare)

• “The most under-rated language ever”
• “This language was clearly designed by very, very lazy
  programmers.”
OVER GROOVY

• Draait in JVM

• Groovy class = Java class

• Perfecte integratie met Java
HELLO WORLD - JAVA

public class HelloWorld {


    private String name;


    public void setName(String name) {
        this.name = name;
    }


    public String getName() {
        return name;
    }


    public String greet() {
        return "Hello " + name;
    }


    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setName("Groovy");
        System.out.println(helloWorld.greet());
    }
}
HELLO WORLD - GROOVY

public class HelloWorld {


    private String name;


    public void setName(String name) {
        this.name = name;
    }


    public String getName() {
        return name;
    }


    public String greet() {
        return "Hello " + name;
    }


    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setName("Groovy");
        System.out.println(helloWorld.greet());
    }
}
HELLO WORLD - GROOVY

public class HelloWorld {


    private String name;


    public void setName(String name) {
        this.name = name;
    }


    public String getName() {
        return name;
    }


    public String greet() {
        return "Hello " + name;
    }


    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setName("Groovy");
        System.out.println(helloWorld.greet());
    }
}
HELLO WORLD - GROOVY

public class HelloWorld {


    String name;


    public String greet() {
        return "Hello " + name;
    }


    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setName("Groovy");
        System.out.println(helloWorld.greet());
    }
}
HELLO WORLD - GROOVY

public class HelloWorld {


    String name;


    public String greet() {
        return "Hello " + name;
    }


    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setName("Groovy");
        System.out.println(helloWorld.greet());
    }
}
HELLO WORLD - GROOVY

class HelloWorld {
    String name


    def greet() {
        return "Hello " + name
    }


    static main(args) {
        def helloWorld = new HelloWorld()
        helloWorld.setName("Groovy")
        System.out.println(helloWorld.greet())
    }
}
HELLO WORLD - GROOVY

class HelloWorld {
    String name


    def greet() {
        return "Hello " + name
    }


    static main(args) {
                                        name:"Groovy")
        def helloWorld = new HelloWorld()
        helloWorld.setName("Groovy")
        System.out.println(helloWorld.greet())
    }
}
HELLO WORLD - GROOVY

class HelloWorld {
    String name


    def greet() { "Hello " + name }


    static main(args) {
        def helloWorld = new HelloWorld(name:"Groovy")
        println(helloWorld.greet())
    }
}
HELLO WORLD - GROOVY

class HelloWorld {
    String name


    def greet() { "Hello " + name }


    static main(args) {
        def helloWorld = new HelloWorld(name:"Groovy")
        println(helloWorld.greet())
    }
}
HELLO WORLD - GROOVY

class HelloWorld {
    def name
    def greet() { "Hello $name" }
}


def helloWorld = new HelloWorld(name:"Groovy")
println helloWorld.greet()
HELLO WORLD - GROOVY

public class HelloWorld {                         class HelloWorld {
                                                      def name
    private String name;                              def greet() { "Hello $name" }
                                                  }
    public void setName(String name) {
        this.name = name;                         def helloWorld = new HelloWorld(name:"Groovy")
    }                                             println helloWorld.greet()


    public String getName() {
        return name;
    }


    public String greet() {
        return "Hello " + name;
    }


    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setName("Groovy");
        System.out.println(helloWorld.greet());
    }
}
GROOVY CONSOLE
GROOVY INTEGRATION

•   Als Programmeertaal
     – Compileert design-time
     – Configuratie in Ant build script
GROOVY INTEGRATION - ANT

<?xml version="1.0" encoding="windows-1252" ?>
<project xmlns="antlib:org.apache.tools.ant" name="Project1">


...


      <path id="groovy.lib" location="${workspace.dir}/groovy-all-2.0.1.jar"/>


...


      <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc“
              classpathref="groovy.lib"/>


...


      <target name="compile">
         <groovyc srcdir="${src.dir}" destdir="${output.dir}">
              <javac source="1.6" target="1.6"/>
         </groovyc>
      </target>


...


</project>
GROOVY INTEGRATION

•   Als Programmeertaal
     – Compileert design-time
     – Configuratie in Ant build script

•   Als Scripttaal
     – Compileert run-time
         • (Groovy compiler is geschreven in Java)
GROOVY INTEGRATION - SCRIPTING




   GroovyShell gs = new GroovyShell();
   Object result = gs.evaluate("...");
GROOVY FEATURES

•   Native syntax
     – Lists
         def list = [1, 2, 3, 4]


     – Maps:
         def map = [nl: 'Nederland', be: 'Belgie']
         assert map['nl'] == 'Nederland'
                && map.be == 'Belgie'


     – Ranges:
         def range = 11..36


     – Regular Expressions
         assert 'abc' ==~ /.wc/
GROOVY FEATURES

•   Native syntax (vervolg)
     – GStrings
         "Hello $name, it is now: ${new Date()}"


     – Multiline Strings
         def string = """Dit is regel 1.
             Dit is regel 2."""


     – Multiple assignment
         def (a, b) = [1, 2]
         (a, b) = [b, a]
         def (p, q, r, s, t) = 1..5
GROOVY FEATURES

•   New Operators
     – Safe navigation (?.)
         person?.adress?.streetname
         in plaats van
         person != null ? (person.getAddress() != null ?
         person.getAddress().getStreetname() : null) :
         null


     – Elvis (?:)
         username ?: 'Anoniem'


     – Spaceship (<=>)
         assert 'a' <=> 'b' == -1
GROOVY FEATURES

•   Operator overloading
     – Uitgebreid toegepast in GDK, voorbeelden:
         def list = ['a', 'b', 1, 2, 3]
         assert list + list == list * 2
         assert list - ['a', 'b'] == [1, 2, 3]

         new Date() + 1 // Een date morgen
GROOVY FEATURES

•   Smart conversion (voorbeelden)
     – to Numbers
        def string = '123'
        def nr = string as int
        assert string.class.name == 'java.lang.String'
        assert nr.class.name == 'java.lang.Integer'


    – to Booleans (Groovy truth)
        assert "" as boolean == false
        if (string) { ... }


    – to JSON
        [a:1, b:2] as Json // {"a":1,"b":2}


    – to interfaces
GROOVY FEATURES

•   Closures
     – (Anonieme) functie
         • Kan worden uitgevoerd
         • Kan parameters accepteren
         • Kan een waarde retourneren


     – Object
         • Kan in variabele worden opgeslagen
         • Kan als parameter worden meegegeven


     – Voorbeeld:
         new File('file.txt').eachLine({ line ->
             println it
                     line
         })


     – Kan variabelen buiten eigen scope gebruiken
GROOVY FEATURES

•    Groovy SQL
      – Zeer mooie interface tegen JDBC

      – Gebruikt GStrings voor queries

      – Voorbeeld:

    def search = 'Ki%'
    def emps = sql.rows ( """select *
                             from employees
                             where first_name like $search
                             or last_name like $search""" )
GROOVY FEATURES

•   Builders
     – ‘Native syntax’ voor het opbouwen van:
         •   XML
         •   GUI (Swing)
         •   Json
         •   Ant taken
         •   …


     – Op basis van Closures
GROOVY QUIZ

•   Geldig?

    def l = [ [a:1, b:2], [a:3, b:4] ]
    def (m, n) = l



    class Bean { def id, name }
      def
    new Bean().setName('Pieter')
    [id:123, name:'Pieter'] as Bean



    geef mij nu een kop koffie, snel
GROOVY FEATURES

•   Categories
     – Tijdelijke DSL (domain specific language)

     – Breidt (bestaande) classes uit met extra functies

     – Voorbeeld:
         use(TimeCategory) {
             newDate = (1.month + 1.week).from.now
         }
GROOVY FEATURES

•   (AST) Transformations
     – Verder reduceren boiler plate code

     – Enkele patterns worden meegeleverd, o.a.:
         • @Singleton
         • @Immutable / @Canonical
         • @Lazy
         • @Delegate (multiple inheritance!)
GROOVY CASES

•   Java omgeving
     – Als je werkt met: (ook in productie)
         •   Beans
         •   XML / HTML / JSON
         •   Bestanden / IO algemeen
         •   Database via JDBC
         •   Hardcore Java classes (minder boilerplate)
         •   DSL
         •   Rich clients (ook JavaFX)

     – Functioneel programmeren in Java

     – Prototyping

     – Extreme dynamic classloading

•   Shell scripting
GROOVY HANDSON
“ADF SCRIPTENGINE”

•   Combinatie van:
     – ADF
     – Groovy
        • met wat nieuwe constructies (“omdat het kan”)


•   Features
     – Programmaflow in Groovy

    – Builder syntax voor tonen schermen in ADF
        • Control state is volledig serialiseerbaar (high availability enzo)


    – Bindings (à la EL ValueBindings)

    – Mooie API (à la Grails) richting Model (bijv. ADF BC,
      WebServices, etc...)
“ADF SCRIPTENGINE”

•   Voorbeeld script
     – Handmatig aanvullen lege elementen in een XML fragment
GROOVY TEASER

•   Method parameters with defaults
•   Method with named parameters
•   Creating Groovy API’s
•   Runtime meta-programming
•   Compile-time meta-programming
•   Interceptors
•   Advanced OO (Groovy interfaces)
•   GUI’s
•   …

More Related Content

What's hot

Python postgre sql a wonderful wedding
Python postgre sql   a wonderful weddingPython postgre sql   a wonderful wedding
Python postgre sql a wonderful weddingStéphane Wirtel
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to GroovyAnton Arhipov
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestHoward Lewis Ship
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4Jan Berdajs
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014Henning Jacobs
 
JNI - Java & C in the same project
JNI - Java & C in the same projectJNI - Java & C in the same project
JNI - Java & C in the same projectKarol Wrótniak
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
awesome groovy
awesome groovyawesome groovy
awesome groovyPaul King
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2osfameron
 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineMovel
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language TriviaNikita Popov
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Chang W. Doh
 
Hey Kotlin, How it works?
Hey Kotlin, How it works?Hey Kotlin, How it works?
Hey Kotlin, How it works?Chang W. Doh
 

What's hot (20)

Python postgre sql a wonderful wedding
Python postgre sql   a wonderful weddingPython postgre sql   a wonderful wedding
Python postgre sql a wonderful wedding
 
Intro to Redis
Intro to RedisIntro to Redis
Intro to Redis
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014
 
JNI - Java & C in the same project
JNI - Java & C in the same projectJNI - Java & C in the same project
JNI - Java & C in the same project
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 
awesome groovy
awesome groovyawesome groovy
awesome groovy
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요
 
Hey Kotlin, How it works?
Hey Kotlin, How it works?Hey Kotlin, How it works?
Hey Kotlin, How it works?
 
groovy & grails - lecture 2
groovy & grails - lecture 2groovy & grails - lecture 2
groovy & grails - lecture 2
 
Python lec4
Python lec4Python lec4
Python lec4
 

Viewers also liked (6)

Ronald van Luttikhuizen - Effective fault handling in SOA Suite and OSB 11g
Ronald van Luttikhuizen - Effective fault handling in SOA Suite and OSB 11gRonald van Luttikhuizen - Effective fault handling in SOA Suite and OSB 11g
Ronald van Luttikhuizen - Effective fault handling in SOA Suite and OSB 11g
 
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
 
Oracle 12c revealed Demonstration
Oracle 12c revealed DemonstrationOracle 12c revealed Demonstration
Oracle 12c revealed Demonstration
 
AMIS OOW Review 2012 - Deel 7 - Lucas Jellema
AMIS OOW Review 2012 - Deel 7 - Lucas JellemaAMIS OOW Review 2012 - Deel 7 - Lucas Jellema
AMIS OOW Review 2012 - Deel 7 - Lucas Jellema
 
Oow2016 review-db-dev-bigdata-BI
Oow2016 review-db-dev-bigdata-BIOow2016 review-db-dev-bigdata-BI
Oow2016 review-db-dev-bigdata-BI
 
AMIS Oracle OpenWorld 2013 Review Part 1 - Intro Overview Innovation, Hardwar...
AMIS Oracle OpenWorld 2013 Review Part 1 - Intro Overview Innovation, Hardwar...AMIS Oracle OpenWorld 2013 Review Part 1 - Intro Overview Innovation, Hardwar...
AMIS Oracle OpenWorld 2013 Review Part 1 - Intro Overview Innovation, Hardwar...
 

Similar to Presentatie - Introductie in Groovy

Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークTsuyoshi Yamamoto
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages VictorSzoltysek
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
Introduction to Oracle Groovy
Introduction to Oracle GroovyIntroduction to Oracle Groovy
Introduction to Oracle GroovyDeepak Bhagat
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovymanishkp84
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、GaelykでハンズオンTsuyoshi Yamamoto
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyIván López Martín
 
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
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java DevelopersAndres Almiray
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyAndres 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
 
Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)Bozhidar Batsov
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developersPuneet Behl
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy GrailsTsuyoshi Yamamoto
 
Groovy And Grails JUG Sardegna
Groovy And Grails JUG SardegnaGroovy And Grails JUG Sardegna
Groovy And Grails JUG SardegnaJohn Leach
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 

Similar to Presentatie - Introductie in Groovy (20)

Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Introduction to Oracle Groovy
Introduction to Oracle GroovyIntroduction to Oracle Groovy
Introduction to Oracle Groovy
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
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
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java Developers
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
 
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
 
Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)
 
Groovy!
Groovy!Groovy!
Groovy!
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developers
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails
 
Groovy intro for OUDL
Groovy intro for OUDLGroovy intro for OUDL
Groovy intro for OUDL
 
Groovy And Grails JUG Sardegna
Groovy And Grails JUG SardegnaGroovy And Grails JUG Sardegna
Groovy And Grails JUG Sardegna
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 

More from Getting value from IoT, Integration and Data Analytics

More from Getting value from IoT, Integration and Data Analytics (20)

AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaSAMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: DataAMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
 
10 tips voor verbetering in je Linkedin profiel
10 tips voor verbetering in je Linkedin profiel10 tips voor verbetering in je Linkedin profiel
10 tips voor verbetering in je Linkedin profiel
 
Iot in de zorg the next step - fit for purpose
Iot in de zorg   the next step - fit for purpose Iot in de zorg   the next step - fit for purpose
Iot in de zorg the next step - fit for purpose
 
Iot overview .. Best practices and lessons learned by Conclusion Conenct
Iot overview .. Best practices and lessons learned by Conclusion Conenct Iot overview .. Best practices and lessons learned by Conclusion Conenct
Iot overview .. Best practices and lessons learned by Conclusion Conenct
 
IoT Fit for purpose - how to be successful in IOT Conclusion Connect
IoT Fit for purpose - how to be successful in IOT Conclusion Connect IoT Fit for purpose - how to be successful in IOT Conclusion Connect
IoT Fit for purpose - how to be successful in IOT Conclusion Connect
 
Industry and IOT Overview of protocols and best practices Conclusion Connect
Industry and IOT Overview of protocols and best practices  Conclusion ConnectIndustry and IOT Overview of protocols and best practices  Conclusion Connect
Industry and IOT Overview of protocols and best practices Conclusion Connect
 
IoT practical case using the people counter sensing traffic density build usi...
IoT practical case using the people counter sensing traffic density build usi...IoT practical case using the people counter sensing traffic density build usi...
IoT practical case using the people counter sensing traffic density build usi...
 
R introduction decision_trees
R introduction decision_treesR introduction decision_trees
R introduction decision_trees
 
Introduction overviewmachinelearning sig Door Lucas Jellema
Introduction overviewmachinelearning sig Door Lucas JellemaIntroduction overviewmachinelearning sig Door Lucas Jellema
Introduction overviewmachinelearning sig Door Lucas Jellema
 
IoT and the Future of work
IoT and the Future of work IoT and the Future of work
IoT and the Future of work
 
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
 
Ethereum smart contracts - door Peter Reitsma
Ethereum smart contracts - door Peter ReitsmaEthereum smart contracts - door Peter Reitsma
Ethereum smart contracts - door Peter Reitsma
 
Blockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
Blockchain - Techniek en usecases door Robert van Molken - AMIS - ConclusionBlockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
Blockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
 
kennissessie blockchain - Wat is Blockchain en smart contracts @Conclusion
kennissessie blockchain -  Wat is Blockchain en smart contracts @Conclusion kennissessie blockchain -  Wat is Blockchain en smart contracts @Conclusion
kennissessie blockchain - Wat is Blockchain en smart contracts @Conclusion
 
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
 
Omc AMIS evenement 26012017 Dennis van Soest
Omc AMIS evenement 26012017 Dennis van SoestOmc AMIS evenement 26012017 Dennis van Soest
Omc AMIS evenement 26012017 Dennis van Soest
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
[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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
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
 
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
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
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?
 
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
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Presentatie - Introductie in Groovy

  • 1. AMIS – 26 november 2012 INTRODUCTIE IN GROOVY
  • 2. OVER JAVA • Academisch • Uitgewerkt concept, Super uitgespecificeerd • Bewezen • Performant, Platform onafhankelijk • Robust, Secure (?) • Antiek • Modern in 1995 • Vergelijk: C#, Python, Ruby, JavaScript, Smalltalk, Go • Autistisch private String name; public void setName(String name) { this.name = name; } import java.io.*; import java.math.BigDecimal; public String getName() { import java.net.*; return name; import java.util.*; }
  • 3. OVER JAVA – VERGELIJKING Java C# public class Pet { public class Pet private PetName name; { private Person owner; public PetName Name { get; set; } public Person Owner { get; set; } public Pet(PetName name, Person owner) { } this.name = name; this.owner = owner; } public PetName getName() { return name; } public void setName(PetName name) { this.name = name; } public Person getOwner() { return owner; } public void setOwner(Person owner) { this.owner = owner; } }
  • 4. OVER JAVA – VERGELIJKING Java Python Map<String, Integer> map = map = {'een':1, 'twee':2, 'drie':3, new HashMap<String, Integer>(); 'vier':4, 'vijf':5, 'zes':6} map.put("een", 1); map.put("twee", 2); map.put("drie", 3); map.put("vier", 4); map.put("vijf", 5); map.put("zes", 6);
  • 5. OVER JAVA – VERGELIJKING Java Python FileInputStream fis = null; with open('file.txt', 'r') as f: InputStreamReader isr = null; for line in f: BufferedReader br = null; print line, try { fis = new FileInputStream("file.txt"); isr = new InputStreamReader(fis); br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } } catch (IOException e) { throw new RuntimeException(e); } finally { if (br != null) try { br.close(); } catch (IOException e) { } if (isr != null) try { isr.close(); } catch (IOException e) { } if (fis != null) try { fis.close(); } catch (IOException e) { } }
  • 6. OVER GROOVY • Sinds: 2003 • Door: James Strachan • Target: Java ontwikkelaars • Basis: Java • Plus: “Al het goede” van Ruby, Python en Smalltalk • Apache Licence • Uitgebreide community • Ondersteund door SpringSource (VMWare) • “The most under-rated language ever” • “This language was clearly designed by very, very lazy programmers.”
  • 7. OVER GROOVY • Draait in JVM • Groovy class = Java class • Perfecte integratie met Java
  • 8. HELLO WORLD - JAVA public class HelloWorld { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println(helloWorld.greet()); } }
  • 9. HELLO WORLD - GROOVY public class HelloWorld { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println(helloWorld.greet()); } }
  • 10. HELLO WORLD - GROOVY public class HelloWorld { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println(helloWorld.greet()); } }
  • 11. HELLO WORLD - GROOVY public class HelloWorld { String name; public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println(helloWorld.greet()); } }
  • 12. HELLO WORLD - GROOVY public class HelloWorld { String name; public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println(helloWorld.greet()); } }
  • 13. HELLO WORLD - GROOVY class HelloWorld { String name def greet() { return "Hello " + name } static main(args) { def helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println(helloWorld.greet()) } }
  • 14. HELLO WORLD - GROOVY class HelloWorld { String name def greet() { return "Hello " + name } static main(args) { name:"Groovy") def helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println(helloWorld.greet()) } }
  • 15. HELLO WORLD - GROOVY class HelloWorld { String name def greet() { "Hello " + name } static main(args) { def helloWorld = new HelloWorld(name:"Groovy") println(helloWorld.greet()) } }
  • 16. HELLO WORLD - GROOVY class HelloWorld { String name def greet() { "Hello " + name } static main(args) { def helloWorld = new HelloWorld(name:"Groovy") println(helloWorld.greet()) } }
  • 17. HELLO WORLD - GROOVY class HelloWorld { def name def greet() { "Hello $name" } } def helloWorld = new HelloWorld(name:"Groovy") println helloWorld.greet()
  • 18. HELLO WORLD - GROOVY public class HelloWorld { class HelloWorld { def name private String name; def greet() { "Hello $name" } } public void setName(String name) { this.name = name; def helloWorld = new HelloWorld(name:"Groovy") } println helloWorld.greet() public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println(helloWorld.greet()); } }
  • 20. GROOVY INTEGRATION • Als Programmeertaal – Compileert design-time – Configuratie in Ant build script
  • 21. GROOVY INTEGRATION - ANT <?xml version="1.0" encoding="windows-1252" ?> <project xmlns="antlib:org.apache.tools.ant" name="Project1"> ... <path id="groovy.lib" location="${workspace.dir}/groovy-all-2.0.1.jar"/> ... <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc“ classpathref="groovy.lib"/> ... <target name="compile"> <groovyc srcdir="${src.dir}" destdir="${output.dir}"> <javac source="1.6" target="1.6"/> </groovyc> </target> ... </project>
  • 22. GROOVY INTEGRATION • Als Programmeertaal – Compileert design-time – Configuratie in Ant build script • Als Scripttaal – Compileert run-time • (Groovy compiler is geschreven in Java)
  • 23. GROOVY INTEGRATION - SCRIPTING GroovyShell gs = new GroovyShell(); Object result = gs.evaluate("...");
  • 24. GROOVY FEATURES • Native syntax – Lists def list = [1, 2, 3, 4] – Maps: def map = [nl: 'Nederland', be: 'Belgie'] assert map['nl'] == 'Nederland' && map.be == 'Belgie' – Ranges: def range = 11..36 – Regular Expressions assert 'abc' ==~ /.wc/
  • 25. GROOVY FEATURES • Native syntax (vervolg) – GStrings "Hello $name, it is now: ${new Date()}" – Multiline Strings def string = """Dit is regel 1. Dit is regel 2.""" – Multiple assignment def (a, b) = [1, 2] (a, b) = [b, a] def (p, q, r, s, t) = 1..5
  • 26. GROOVY FEATURES • New Operators – Safe navigation (?.) person?.adress?.streetname in plaats van person != null ? (person.getAddress() != null ? person.getAddress().getStreetname() : null) : null – Elvis (?:) username ?: 'Anoniem' – Spaceship (<=>) assert 'a' <=> 'b' == -1
  • 27. GROOVY FEATURES • Operator overloading – Uitgebreid toegepast in GDK, voorbeelden: def list = ['a', 'b', 1, 2, 3] assert list + list == list * 2 assert list - ['a', 'b'] == [1, 2, 3] new Date() + 1 // Een date morgen
  • 28. GROOVY FEATURES • Smart conversion (voorbeelden) – to Numbers def string = '123' def nr = string as int assert string.class.name == 'java.lang.String' assert nr.class.name == 'java.lang.Integer' – to Booleans (Groovy truth) assert "" as boolean == false if (string) { ... } – to JSON [a:1, b:2] as Json // {"a":1,"b":2} – to interfaces
  • 29. GROOVY FEATURES • Closures – (Anonieme) functie • Kan worden uitgevoerd • Kan parameters accepteren • Kan een waarde retourneren – Object • Kan in variabele worden opgeslagen • Kan als parameter worden meegegeven – Voorbeeld: new File('file.txt').eachLine({ line -> println it line }) – Kan variabelen buiten eigen scope gebruiken
  • 30. GROOVY FEATURES • Groovy SQL – Zeer mooie interface tegen JDBC – Gebruikt GStrings voor queries – Voorbeeld: def search = 'Ki%' def emps = sql.rows ( """select * from employees where first_name like $search or last_name like $search""" )
  • 31. GROOVY FEATURES • Builders – ‘Native syntax’ voor het opbouwen van: • XML • GUI (Swing) • Json • Ant taken • … – Op basis van Closures
  • 32. GROOVY QUIZ • Geldig? def l = [ [a:1, b:2], [a:3, b:4] ] def (m, n) = l class Bean { def id, name } def new Bean().setName('Pieter') [id:123, name:'Pieter'] as Bean geef mij nu een kop koffie, snel
  • 33. GROOVY FEATURES • Categories – Tijdelijke DSL (domain specific language) – Breidt (bestaande) classes uit met extra functies – Voorbeeld: use(TimeCategory) { newDate = (1.month + 1.week).from.now }
  • 34. GROOVY FEATURES • (AST) Transformations – Verder reduceren boiler plate code – Enkele patterns worden meegeleverd, o.a.: • @Singleton • @Immutable / @Canonical • @Lazy • @Delegate (multiple inheritance!)
  • 35. GROOVY CASES • Java omgeving – Als je werkt met: (ook in productie) • Beans • XML / HTML / JSON • Bestanden / IO algemeen • Database via JDBC • Hardcore Java classes (minder boilerplate) • DSL • Rich clients (ook JavaFX) – Functioneel programmeren in Java – Prototyping – Extreme dynamic classloading • Shell scripting
  • 37. “ADF SCRIPTENGINE” • Combinatie van: – ADF – Groovy • met wat nieuwe constructies (“omdat het kan”) • Features – Programmaflow in Groovy – Builder syntax voor tonen schermen in ADF • Control state is volledig serialiseerbaar (high availability enzo) – Bindings (à la EL ValueBindings) – Mooie API (à la Grails) richting Model (bijv. ADF BC, WebServices, etc...)
  • 38. “ADF SCRIPTENGINE” • Voorbeeld script – Handmatig aanvullen lege elementen in een XML fragment
  • 39. GROOVY TEASER • Method parameters with defaults • Method with named parameters • Creating Groovy API’s • Runtime meta-programming • Compile-time meta-programming • Interceptors • Advanced OO (Groovy interfaces) • GUI’s • …