SlideShare uma empresa Scribd logo
1 de 37
JGGUG
Grails/Groovy         3




   NTT


          2009/9/25
NTT

                        Gr

               Grails

            JavaWorld Groovy                               (2004)

            Twitter: uehaj




Slide# 2   JGGUG        Grails/Groovy   3   / 2009.09.25
Groovy




           Groovy
                                    Java




                                                         (Groovy Web Console)
     3
Slide#   JGGUG      Grails/Groovy     3   / 2009.09.25
(                 )
                                   (               ,      )




                            (                 )
                            (                       )

Slide# 4   JGGUG   Grails/Groovy       3   / 2009.09.25
Groovy
               X Y                   Z
               Z(Y(X))   …                        ←
               X.Y().Z() …                             →

                  :          Groovy
           × println(each(sort(grep({it%2=0},[1,3,2]))))
           ○   [1,3,2].grep{it%2==0}.sort().each{println it}




Slide# 5        JGGUG    Grails/Groovy   3   / 2009.09.25
each/reverseEach/                           collect
            eachWithIndex/                              find/findAll
                                                        grep/max/min
            reverse/push/pop/join                       any/every


                                                        contains/in/groupBy
                                                        flatten/intersect/disjoint
            each/keySet/entrySet/
            values                                      combinations/
                                                        transpose




Slide# 6   JGGUG     Grails/Groovy   3   / 2009.09.25
:
                                                          ArrayList
              println([1,2,3].class)
             =>java.util.ArrayList
           as                                             :

              [1,2,3] as Set                   // Set

              [1,2,3] as LinkedList        // LinkedList

              [1,2,3].asImmutable()       //

Slide# 7    JGGUG      Grails/Groovy   3   / 2009.09.25
:

                                             LinkedHashMap
            println([a:1,b:2,c:3].getClass())
            =>java.util.LinkedHashMap



            Map m = [a:1, b:2, c:3]
            assert m.get(’a’) == 1   //
            assert m[’a’] == 1       //
            assert m.a == 1          //


Slide# 8   JGGUG    Grails/Groovy   3   / 2009.09.25
map.get(key)
                   map.put(key,             Java
                           value)


                   map[’a’]
                   map[key]
                        
                     
                   map.a
                   map.”$key”               GString



Slide# 9   JGGUG     Grails/Groovy   3   / 2009.09.25
,     ,
              class City                    cities


            class City {
              def name;
              def country;
              long population;
            }
            cities = [
              new City("   ","            ",35676000),
             new City("                   ","                  ",19040000),
             new City("                    =                   ","
               :
Slide# 10    JGGUG        Grails/Groovy     3   / 2009.09.25
(                  )


                                     /


                ≒ Java

                     Closure
                println {->}.class
                ==> groovy.lang.Closure

Slide# 11   JGGUG    Grails/Groovy       3   / 2009.09.25
{-> ..}

                                                           (   )
                {-> println ”ABC” }
                ==>
                                      .call()
                {->println ”ABC” }.call()

                ==> ABC

Slide# 12   JGGUG     Grails/Groovy    3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script
  result = 1
  10.times {
    result *= 2
  }
  assert result ==




Slide# 13   JGGUG      Grails/Groovy   3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script
  result = 1
  10.times {                      Integer(10)
    result *= 2
  }
  assert result ==




Slide# 13   JGGUG      Grails/Groovy    3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script                                                    Integer         (10)
  result = 1
  10.times {                      Integer(10)              def
    result *= 2                                            times(Closure c){
  }                                                          c.call() 10
  assert result ==                                         }




Slide# 13   JGGUG      Grails/Groovy    3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script                                                    Integer         (10)
  result = 1
  10.times {                      Integer(10)              def
    result *= 2                                            times(Closure c){
  }                                                          c.call() 10
  assert result ==                                         }




Slide# 13   JGGUG      Grails/Groovy    3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script                                                      Integer         (10)
  result = 1
  10.times {                      Integer(10)                def
    result *= 2                                              times(Closure c){
  }                                                            c.call() 10
  assert result ==                                           }



                                {
                                       result *= 2
                                }

Slide# 13   JGGUG      Grails/Groovy      3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script                                                       Integer         (10)
  result = 1
  10.times {                      Integer(10)                 def
    result *= 2                                               times(Closure c){
  }                                                             c.call() 10
  assert result ==                       Integer#times        }



                                {
                                       result *= 2
                                }

Slide# 13   JGGUG      Grails/Groovy       3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script                                                       Integer         (10)
  result = 1
  10.times {                      Integer(10)                 def
    result *= 2                                               times(Closure c){
  }                                                             c.call() 10
  assert result ==                       Integer#times        }



                                {                                   (call)
                                       result *= 2
                                }

Slide# 13   JGGUG      Grails/Groovy       3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script                                                       Integer         (10)
  result = 1
  10.times {                      Integer(10)                 def
    result *= 2                                               times(Closure c){
  }                                                             c.call() 10
  assert result ==                       Integer#times        }



                                {                                   (call)
                                                                     (call)
                                       result *= 2
                                }

Slide# 13   JGGUG      Grails/Groovy       3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2
                          }
                          assert result == 1024
 Script                                                       Integer          (10)
  result = 1
  10.times {                      Integer(10)                 def
    result *= 2                                               times(Closure c){
  }                                                             c.call() 10
  assert result ==                       Integer#times        }



                                {                                   (call)
                                                                     (call)
                                       result *= 2                    (call)
                                }

Slide# 13   JGGUG      Grails/Groovy       3   / 2009.09.25
:
             Script.groovy result = 1
                          10.times {
                            result *= 2                           (result)
                          }
                          assert result == 1024
 Script                                                       Integer          (10)
  result = 1
  10.times {                      Integer(10)                 def
    result *= 2                                               times(Closure c){
  }                                                             c.call() 10
  assert result ==                       Integer#times        }



                                {                                   (call)
                                                                     (call)
                                       result *= 2                    (call)
                                }

Slide# 13   JGGUG      Grails/Groovy       3   / 2009.09.25
:
    import javax.swing.*
    import java.awt.event.*

    f = new JFrame(size:[200, 100])
    title = "hello"
    b = new JButton(title)
    b.addActionListener({println title} as ActionListener)
    f.contentPane.add(b)

    f.show()

                           as
            1                                                  implements
                                                                  key,
                value
Slide# 14       JGGUG   Grails/Groovy   3       / 2009.09.25
ExpandoMetaClass
                    (                   )




                                                                    DSL


                :

Slide# 15   JGGUG       Grails/Groovy   3   / 2009.09.25
?




Slide# 16   JGGUG   Grails/Groovy   3   / 2009.09.25
?




Slide# 16   JGGUG   Grails/Groovy   3   / 2009.09.25
:                ==~ =~
                 String.replaceAll(  )
             :/     /


                                 ( )                      GString   $

      ”ABCDE”
       ’ABCDE’
       /ABCDE/

Slide# 17   JGGUG       Grails/Groovy   3   / 2009.09.25
:
            String#replaceAll(String, Closure)
     "abcDefGhi".replaceAll(/([a-z])([A-Z])/) {fullMatch, g1, g2->
       g1 + '_' + g2.toLowerCase()
     }
     ==> "abc_def_ghi"




                Java String#replaceAll(String, String) OK($1,$2   )


Slide# 18      JGGUG       Grails/Groovy   3   / 2009.09.25
final




                      :



Slide# 19   JGGUG          Grails/Groovy   3   / 2009.09.25
: java.lang.String
                                         final


                    String

                    String




Slide# 20   JGGUG        Grails/Groovy    3   / 2009.09.25
tr                   (                                    )
                  String#tr()
     String.metaClass.tr = {from,to ->
       def result = delegate
       from.eachWithIndex{it,idx->
         result = result.replaceAll(it, to.getAt(idx))
       }
       result
     }

     println "abcdef               123".tr("abc              ","xyz       ")
     //==> "xyzdef             123"




Slide# 21        JGGUG    Grails/Groovy   3   / 2009.09.25
:
                          java.lang.String




Slide# 22   JGGUG   Grails/Groovy   3   / 2009.09.25
'ls'.metaClass.exec = { new File(".").eachFile{println it} }
       'pwd'.metaClass.exec = { println new File(".").absolutePath }
       'env'.metaClass.exec = {
         System.getenv().each{k,v->println "$k=$v" }
       }

       System.in.eachLine {
         it.intern().exec()
       }



                                                             →
                     : String#intern()

Slide# 23    JGGUG        Grails/Groovy   3   / 2009.09.25
Groovy                                  (              1)
                    groovyc
                                                      Groovy



                    groovyc jad(                                  )
                     groovyc             jad               Java

                             Groovy 1.6.x



Slide# 24   JGGUG        Grails/Groovy     3   / 2009.09.25
Groovy                               (      2)
               GDK
                DGM      DefaultGroovyMethods.java(
                DefaultGroovyStaticMethods)


                <GROOVY_SRC>/src/main/org/codehaus/groovy/
                runtime/DefaultGroovyMethods.java
               Groovy

                ant -Dskiptests=true

                GROOVY_HOME
                <GROOVY_SRC>/target/install


Slide# 25   JGGUG       Grails/Groovy   3   / 2009.09.25
Groovy                              (             )
                    Grape(Groovy 1.6-,)
                                   Jar                      (
                     )
                     import      @Grab(‘group:mod:ver’)             (1.7)
               Power Assert(1.7beta1-)
             assert
                a=5; assert a+Math.max(a+1, 5)+2==12
                ==>
                Assertion failed:
                assert a+Math.max(a+1, 5)+2==12
                       ||     |   ||     | |
                       |11    6   |6     | false
                       5          5      13
                
 at Script1.run(Script1.groovy:2)

Slide# 26   JGGUG        Grails/Groovy   3   / 2009.09.25
Groovy




                DB       (GroovySql)
                                      (SimpleTemplate)
                                              XML          (XmlSlurper,
                XmlParser)


Slide# 27   JGGUG     Grails/Groovy     3   / 2009.09.25

Mais conteúdo relacionado

Semelhante a Jggug Nagoya 20090925 Groovy

Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume LaforgeGroovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume LaforgeGuillaume Laforge
 
G*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョンG*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョンTsuyoshi Yamamoto
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talkdesistartups
 
Introduction to Grails
Introduction to Grails Introduction to Grails
Introduction to Grails Avi Perez
 
G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~Tsuyoshi Yamamoto
 
Groovy Api Tutorial
Groovy Api  TutorialGroovy Api  Tutorial
Groovy Api Tutorialguligala
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionSchalk Cronjé
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersKostas Saidis
 
Groovy as a scripting language
Groovy as a scripting languageGroovy as a scripting language
Groovy as a scripting languageJenn Strater
 
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
 
Startup groovysession1
Startup groovysession1Startup groovysession1
Startup groovysession1kyon mm
 
LISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesLISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesTobias Oetiker
 
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume LaforgeGroovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume LaforgeGuillaume Laforge
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGuillaume Laforge
 

Semelhante a Jggug Nagoya 20090925 Groovy (20)

Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume LaforgeGroovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
 
Groovy
GroovyGroovy
Groovy
 
G*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョンG*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョン
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
 
Introduction to Grails
Introduction to Grails Introduction to Grails
Introduction to Grails
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~
 
Groovy Api Tutorial
Groovy Api  TutorialGroovy Api  Tutorial
Groovy Api Tutorial
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
 
Groovy as a scripting language
Groovy as a scripting languageGroovy as a scripting language
Groovy as a scripting language
 
Groovy
GroovyGroovy
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
 
OpenLogic
OpenLogicOpenLogic
OpenLogic
 
Startup groovysession1
Startup groovysession1Startup groovysession1
Startup groovysession1
 
LISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesLISA QooxdooTutorial Slides
LISA QooxdooTutorial Slides
 
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume LaforgeGroovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 

Mais de Uehara Junji

Groovy Bootcamp 2015 by JGGUG
Groovy Bootcamp 2015 by JGGUGGroovy Bootcamp 2015 by JGGUG
Groovy Bootcamp 2015 by JGGUGUehara Junji
 
Groovy Shell Scripting 2015
Groovy Shell Scripting 2015Groovy Shell Scripting 2015
Groovy Shell Scripting 2015Uehara Junji
 
Shibuya JVM Groovy 20150418
Shibuya JVM Groovy 20150418Shibuya JVM Groovy 20150418
Shibuya JVM Groovy 20150418Uehara Junji
 
Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait Uehara Junji
 
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ckIndy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ckUehara Junji
 
enterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 Summerenterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 SummerUehara Junji
 
New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1Uehara Junji
 
Groovy kisobenkyoukai20130309
Groovy kisobenkyoukai20130309Groovy kisobenkyoukai20130309
Groovy kisobenkyoukai20130309Uehara Junji
 
Read Groovy Compile process(Groovy Benkyoukai 2013)
Read Groovy Compile process(Groovy Benkyoukai 2013)Read Groovy Compile process(Groovy Benkyoukai 2013)
Read Groovy Compile process(Groovy Benkyoukai 2013)Uehara Junji
 
groovy 2.1.0 20130118
groovy 2.1.0 20130118groovy 2.1.0 20130118
groovy 2.1.0 20130118Uehara Junji
 
G* Workshop in fukuoka 20120901
G* Workshop in fukuoka 20120901G* Workshop in fukuoka 20120901
G* Workshop in fukuoka 20120901Uehara Junji
 
JJUG CCC 2012 Real World Groovy/Grails
JJUG CCC 2012 Real World Groovy/GrailsJJUG CCC 2012 Real World Groovy/Grails
JJUG CCC 2012 Real World Groovy/GrailsUehara Junji
 
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Java One 2012 Tokyo JVM Lang. BOF(Groovy)Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Java One 2012 Tokyo JVM Lang. BOF(Groovy)Uehara Junji
 
Java x Groovy: improve your java development life
Java x Groovy: improve your java development lifeJava x Groovy: improve your java development life
Java x Groovy: improve your java development lifeUehara Junji
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能についてUehara Junji
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Uehara Junji
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEUehara Junji
 
Easy Going Groovy(Groovyを気軽に使いこなそう)
Easy Going Groovy(Groovyを気軽に使いこなそう)Easy Going Groovy(Groovyを気軽に使いこなそう)
Easy Going Groovy(Groovyを気軽に使いこなそう)Uehara Junji
 
GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.Uehara Junji
 

Mais de Uehara Junji (20)

Groovy Bootcamp 2015 by JGGUG
Groovy Bootcamp 2015 by JGGUGGroovy Bootcamp 2015 by JGGUG
Groovy Bootcamp 2015 by JGGUG
 
Groovy Shell Scripting 2015
Groovy Shell Scripting 2015Groovy Shell Scripting 2015
Groovy Shell Scripting 2015
 
Shibuya JVM Groovy 20150418
Shibuya JVM Groovy 20150418Shibuya JVM Groovy 20150418
Shibuya JVM Groovy 20150418
 
Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait
 
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ckIndy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
 
enterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 Summerenterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 Summer
 
New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1
 
Groovy kisobenkyoukai20130309
Groovy kisobenkyoukai20130309Groovy kisobenkyoukai20130309
Groovy kisobenkyoukai20130309
 
Read Groovy Compile process(Groovy Benkyoukai 2013)
Read Groovy Compile process(Groovy Benkyoukai 2013)Read Groovy Compile process(Groovy Benkyoukai 2013)
Read Groovy Compile process(Groovy Benkyoukai 2013)
 
groovy 2.1.0 20130118
groovy 2.1.0 20130118groovy 2.1.0 20130118
groovy 2.1.0 20130118
 
G* Workshop in fukuoka 20120901
G* Workshop in fukuoka 20120901G* Workshop in fukuoka 20120901
G* Workshop in fukuoka 20120901
 
JJUG CCC 2012 Real World Groovy/Grails
JJUG CCC 2012 Real World Groovy/GrailsJJUG CCC 2012 Real World Groovy/Grails
JJUG CCC 2012 Real World Groovy/Grails
 
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Java One 2012 Tokyo JVM Lang. BOF(Groovy)Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
 
Java x Groovy: improve your java development life
Java x Groovy: improve your java development lifeJava x Groovy: improve your java development life
Java x Groovy: improve your java development life
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能について
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVE
 
Easy Going Groovy(Groovyを気軽に使いこなそう)
Easy Going Groovy(Groovyを気軽に使いこなそう)Easy Going Groovy(Groovyを気軽に使いこなそう)
Easy Going Groovy(Groovyを気軽に使いこなそう)
 
GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.
 
Clojure
ClojureClojure
Clojure
 

Último

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Último (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Jggug Nagoya 20090925 Groovy

  • 1. JGGUG Grails/Groovy 3 NTT 2009/9/25
  • 2. NTT Gr Grails JavaWorld Groovy (2004) Twitter: uehaj Slide# 2 JGGUG Grails/Groovy 3 / 2009.09.25
  • 3. Groovy Groovy Java (Groovy Web Console) 3 Slide# JGGUG Grails/Groovy 3 / 2009.09.25
  • 4. ( ) ( , ) ( ) ( ) Slide# 4 JGGUG Grails/Groovy 3 / 2009.09.25
  • 5. Groovy X Y Z Z(Y(X)) … ← X.Y().Z() … → : Groovy × println(each(sort(grep({it%2=0},[1,3,2])))) ○ [1,3,2].grep{it%2==0}.sort().each{println it} Slide# 5 JGGUG Grails/Groovy 3 / 2009.09.25
  • 6. each/reverseEach/ collect eachWithIndex/ find/findAll grep/max/min reverse/push/pop/join any/every contains/in/groupBy flatten/intersect/disjoint each/keySet/entrySet/ values combinations/ transpose Slide# 6 JGGUG Grails/Groovy 3 / 2009.09.25
  • 7. : ArrayList  println([1,2,3].class) =>java.util.ArrayList as :  [1,2,3] as Set                   // Set  [1,2,3] as LinkedList        // LinkedList  [1,2,3].asImmutable()       // Slide# 7 JGGUG Grails/Groovy 3 / 2009.09.25
  • 8. : LinkedHashMap println([a:1,b:2,c:3].getClass()) =>java.util.LinkedHashMap Map m = [a:1, b:2, c:3]  assert m.get(’a’) == 1   //  assert m[’a’] == 1       //  assert m.a == 1          // Slide# 8 JGGUG Grails/Groovy 3 / 2009.09.25
  • 9. map.get(key) map.put(key, Java value) map[’a’] map[key]          map.a map.”$key” GString Slide# 9 JGGUG Grails/Groovy 3 / 2009.09.25
  • 10. , , class City cities class City { def name; def country; long population; } cities = [ new City(" "," ",35676000), new City(" "," ",19040000), new City(" = "," : Slide# 10 JGGUG Grails/Groovy 3 / 2009.09.25
  • 11. ( ) / ≒ Java Closure println {->}.class ==> groovy.lang.Closure Slide# 11 JGGUG Grails/Groovy 3 / 2009.09.25
  • 12. {-> ..} ( ) {-> println ”ABC” } ==> .call() {->println ”ABC” }.call() ==> ABC Slide# 12 JGGUG Grails/Groovy 3 / 2009.09.25
  • 13. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script result = 1 10.times { result *= 2 } assert result == Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 14. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script result = 1 10.times { Integer(10) result *= 2 } assert result == Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 15. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 16. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 17. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == } { result *= 2 } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 18. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { result *= 2 } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 19. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { (call) result *= 2 } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 20. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { (call) (call) result *= 2 } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 21. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { (call) (call) result *= 2 (call) } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 22. : Script.groovy result = 1 10.times {   result *= 2 (result) } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { (call) (call) result *= 2 (call) } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 23. : import javax.swing.* import java.awt.event.* f = new JFrame(size:[200, 100]) title = "hello" b = new JButton(title) b.addActionListener({println title} as ActionListener) f.contentPane.add(b) f.show() as 1 implements key, value Slide# 14 JGGUG Grails/Groovy 3 / 2009.09.25
  • 24. ExpandoMetaClass ( ) DSL : Slide# 15 JGGUG Grails/Groovy 3 / 2009.09.25
  • 25. ? Slide# 16 JGGUG Grails/Groovy 3 / 2009.09.25
  • 26. ? Slide# 16 JGGUG Grails/Groovy 3 / 2009.09.25
  • 27. : ==~ =~ String.replaceAll( ) :/ / ( ) GString $ ”ABCDE” ’ABCDE’ /ABCDE/ Slide# 17 JGGUG Grails/Groovy 3 / 2009.09.25
  • 28. : String#replaceAll(String, Closure) "abcDefGhi".replaceAll(/([a-z])([A-Z])/) {fullMatch, g1, g2-> g1 + '_' + g2.toLowerCase() } ==> "abc_def_ghi" Java String#replaceAll(String, String) OK($1,$2 ) Slide# 18 JGGUG Grails/Groovy 3 / 2009.09.25
  • 29. final : Slide# 19 JGGUG Grails/Groovy 3 / 2009.09.25
  • 30. : java.lang.String final String String Slide# 20 JGGUG Grails/Groovy 3 / 2009.09.25
  • 31. tr ( ) String#tr() String.metaClass.tr = {from,to ->   def result = delegate   from.eachWithIndex{it,idx->     result = result.replaceAll(it, to.getAt(idx))   }   result } println "abcdef 123".tr("abc ","xyz ") //==> "xyzdef 123" Slide# 21 JGGUG Grails/Groovy 3 / 2009.09.25
  • 32. : java.lang.String Slide# 22 JGGUG Grails/Groovy 3 / 2009.09.25
  • 33. 'ls'.metaClass.exec = { new File(".").eachFile{println it} } 'pwd'.metaClass.exec = { println new File(".").absolutePath } 'env'.metaClass.exec = { System.getenv().each{k,v->println "$k=$v" } } System.in.eachLine {   it.intern().exec() } → : String#intern() Slide# 23 JGGUG Grails/Groovy 3 / 2009.09.25
  • 34. Groovy ( 1) groovyc Groovy groovyc jad( ) groovyc jad Java Groovy 1.6.x Slide# 24 JGGUG Grails/Groovy 3 / 2009.09.25
  • 35. Groovy ( 2) GDK DGM DefaultGroovyMethods.java( DefaultGroovyStaticMethods) <GROOVY_SRC>/src/main/org/codehaus/groovy/ runtime/DefaultGroovyMethods.java Groovy ant -Dskiptests=true GROOVY_HOME <GROOVY_SRC>/target/install Slide# 25 JGGUG Grails/Groovy 3 / 2009.09.25
  • 36. Groovy ( ) Grape(Groovy 1.6-,) Jar ( ) import @Grab(‘group:mod:ver’) (1.7) Power Assert(1.7beta1-) assert a=5; assert a+Math.max(a+1, 5)+2==12 ==> Assertion failed: assert a+Math.max(a+1, 5)+2==12 || | || | | |11 6 |6 | false 5 5 13 at Script1.run(Script1.groovy:2) Slide# 26 JGGUG Grails/Groovy 3 / 2009.09.25
  • 37. Groovy DB (GroovySql) (SimpleTemplate) XML (XmlSlurper, XmlParser) Slide# 27 JGGUG Grails/Groovy 3 / 2009.09.25