SlideShare a Scribd company logo
Groovy




                Java

2011   5   28
Java
                            2011 05/28
                Slide # 2
2011   5   28
Java
                            2011 05/28
                Slide # 3
2011   5   28
$ cat input.txt
                      That that is is that that is
                      not is not is that it it is

                      $ java WordCount input.txt
                      1: [That]
                      2: [not]
                      2: [it]
                      4: [that]
                      6: [is]                                     Java
                                                     2011 05/28
                Slide # 4
2011   5   28
Java                WordCount:48        Set<Map.Entry<String, Integer>> entrySet =
 import         java.util.Comparator;              map.entrySet();
 import         java.util.HashMap;                      Object[] list = entrySet.toArray();
 import         java.util.Map;                           Comparator comp = new Comparator(){
 import         java.util.Set;                            public int compare(Object o1, Object o2)
 import         java.util.List;                    {
 import         java.util.Arrays;                           Map.Entry<String, Integer> e1 =
 import         java.io.FileReader;                (Map.Entry<String, Integer>) o1;
 import         java.io.BufferedReader;                     Map.Entry<String, Integer> e2 =
 import         java.io.FileNotFoundException;     (Map.Entry<String, Integer>) o2;
 import         java.io.IOException;                         return e1.getValue() - e2.getValue();
                                                           }
 public class WordCount {                                };
   @SuppressWarnings(value = "unchecked")                Arrays.sort(list, comp);
   public static void main(String[] args) {              for (Object it: list) {
     FileReader fis = null;                                Map.Entry<String, Integer> entry =
     BufferedReader br = null;                     (Map.Entry<String, Integer>)it;
     try {                                                 System.out.println(entry.getValue() + ":
       HashMap<String, Integer> map = new          ["+entry.getKey()+"]");
 HashMap<String, Integer>();                             }
       fis = new FileReader(args[0]);                  }
       br = new BufferedReader(fis);                   catch (IOException e) {
       String line;                                      try {if (br != null) br.close();}catch
       while ((line = br.readLine()) != null) {    (IOException ioe){}
         for (String it: line.split("s+")) {           try {if (fis != null)fis.close();}catch
           map.put(it, (map.get(it)==null) ? 1 :   (IOException ioe){}
 (map.get(it) + 1));                                     e.printStackTrace();
         }                                             }

                                                                                            Java
       }                                             }
                                                   }
                                                                    2011 05/28
                Slide # 5
2011   5   28
Groovy         WordCount(9                )
           def map = [:].withDefault{0}
           new File(args[0]).eachLine {
             it.split(/s+/).each {
               map[it]++
          }
           }
           map.entrySet().sort{it.value}.each {
             println "${it.value}: [${it.key}]"
           }




                                                               Java
                                                  2011 05/28
                Slide # 6
2011   5   28
Java
                                                               Set<Map.Entry<String, Integer>>
 import         java.util.Comparator;              entrySet = map.entrySet();
 import         java.util.HashMap;                             Object[] list = entrySet.toArray();
 import         java.util.Map;                                 Comparator comp = new Comparator(){
 import         java.util.Set;                                     public int compare(Object o1,
 import         java.util.List;                    Object o2) {
 import         java.util.Arrays;                                      Map.Entry<String, Integer> e1
 import         java.io.FileReader;                = (Map.Entry<String, Integer>) o1;
 import         java.io.BufferedReader;                                Map.Entry<String, Integer> e2
 import         java.io.FileNotFoundException;     = (Map.Entry<String, Integer>) o2;
 import         java.io.IOException;                                   return e1.getValue() -
                                                   e2.getValue();
 public class WordCount {                                          }
     @SuppressWarnings(value = "unchecked")                    };
     public static void main(String[] args) {                  Arrays.sort(list, comp);
         FileReader fis = null;                                for (Object it: list) {
         BufferedReader br = null;                                 Map.Entry<String, Integer> entry
         try {                                     = (Map.Entry<String, Integer>)it;
             HashMap<String, Integer> map = new                    System.out.println(entry.getValue
 HashMap<String, Integer>();                       () + ": ["+entry.getKey()+"]");
             fis = new FileReader(args[0]);                    }
             br = new BufferedReader(fis);                 }
             String line;                                  catch (IOException e) {
             while ((line = br.readLine()) !=                  try {if (br != null) br.close();}
 null) {                                           catch(IOException ioe){}
                 for (String it: line.split("s               try {if (fis != null)fis.close();}
 +")) {                                            catch(IOException ioe){}
                     map.put(it, (map.get(it)                  e.printStackTrace();
 ==null) ? 1 : (map.get(it) + 1));
                 }
                                                           }
                                                       }
                                                                                           Java
             }                                     }                2011 05/28
                Slide # 7
2011   5   28
Groovy         WordCount(9                           )
           def map = [:].withDefault{0} // value                    0         map
           new File(args[0]).eachLine { //
             it.split(/s+/).each {     //          /s+/
               map[it]++                //     map                        1
             }
           }
           map.entrySet().sort{it.value}.each {// map       entrySet      value
             println "${it.value}: [${it.key}]"//               key,value
           }




                                                                                  Java
                                                             2011 05/28
                Slide # 8
2011   5   28
Groovy         WordCount(9                           )
           def map = [:].withDefault{0} // value                    0         map
           new File(args[0]).eachLine { //
             it.split(/s+/).each {     //          /s+/
               map[it]++                //     map                        1
             }
           }
           map.entrySet().sort{it.value}.each {// map       entrySet      value
             println "${it.value}: [${it.key}]"//               key,value
           }




                                                                                  Java
                                                             2011 05/28
                Slide # 9
2011   5   28
Groovy         WordCount(9                           )
           def map = [:].withDefault{0} // value                    0         map
           new File(args[0]).eachLine { //
             it.split(/s+/).each {     //          /s+/
               map[it]++                //     map                        1
             }
           }
           map.entrySet().sort{it.value}.each {// map       entrySet      value
             println "${it.value}: [${it.key}]"//               key,value
           }




                                                                                  Java
                                                             2011 05/28
                Slide # 10
2011   5   28
Groovy         WordCount(9                           )
           def map = [:].withDefault{0} // value                    0         map
           new File(args[0]).eachLine { //
             it.split(/s+/).each {     //          /s+/
               map[it]++                //     map                        1
             }
           }
           map.entrySet().sort{it.value}.each {// map       entrySet      value
             println "${it.value}: [${it.key}]"//               key,value
           }




                                                                                  Java
                                                             2011 05/28
                Slide # 11
2011   5   28
Groovy         WordCount(9                           )
           def map = [:].withDefault{0} // value                    0         map
           new File(args[0]).eachLine { //
             it.split(/s+/).each {     //          /s+/
               map[it]++                //     map                        1
             }
           }
           map.entrySet().sort{it.value}.each {// map       entrySet      value
             println "${it.value}: [${it.key}]"//               key,value
           }




                                                                                  Java
                                                             2011 05/28
                Slide # 12
2011   5   28
Groovy         WordCount(9                           )
           def map = [:].withDefault{0} // value                    0         map
           new File(args[0]).eachLine { //
             it.split(/s+/).each {     //          /s+/
               map[it]++                //     map                        1
             }
           }
           map.entrySet().sort{it.value}.each {// map       entrySet      value
             println "${it.value}: [${it.key}]"//               key,value
           }




                                                                                  Java
                                                             2011 05/28
                Slide # 13
2011   5   28
Groovy         WordCount(9                           )
           def map = [:].withDefault{0} // value                    0         map
           new File(args[0]).eachLine { //
             it.split(/s+/).each {     //          /s+/
               map[it]++                //     map                        1
             }
           }
           map.entrySet().sort{it.value}.each {// map       entrySet      value
             println "${it.value}: [${it.key}]"//               key,value
           }




                                                                                  Java
                                                             2011 05/28
                Slide # 14
2011   5   28
Java
                             2011 05/28
                Slide # 15
2011   5   28
public final class Person {                                       if (obj == null)
           private final String firstName;                                   return false;
           private final String lastName;                                if (getClass() != obj.getClass())
                                                                             return false;
            public Person(String firstName, String lastName) {           Person other = (Person) obj;
                this.firstName = firstName;                              if (firstName == null) {
                this.lastName = lastName;                                    if (other.firstName != null)
            }                                                                    return false;
                                                                         } else if (!firstName.equals(other.firstName))
            public String getFirstName() {                                   return false;
                return firstName;                                        if (lastName == null) {
            }                                                                if (other.lastName != null)
                                                                                 return false;
            public String getLastName() {                                } else if (!lastName.equals(other.lastName))
                return lastName;                                             return false;
            }                                                            return true;
                                                                     }
            @Override
            public int hashCode() {                                  @Override
                final int prime = 31;                                public String toString() {
                int result = 1;                                          return "Person(firstName:" + firstName
                result = prime * result + ((firstName == null)               + ", lastName:" + lastName + ")";
                    ? 0 : firstName.hashCode());                     }
                result = prime * result + ((lastName == null)
                    ? 0 : lastName.hashCode());                  }
                return result;
            }

            @Override
            public boolean equals(Object obj) {
                if (this == obj)
                    return true;


                                                                                                              Java
                                                                                   2011 05/28
                 Slide # 16
2011    5   28
public final class Person {                                       if (obj == null)
           private final String firstName;                                   return false;
           private final String lastName;                                if (getClass() != obj.getClass())
                                                                             return false;
            public Person(String firstName, String lastName) {           Person other = (Person) obj;
                this.firstName = firstName;                              if (firstName == null) {
                this.lastName = lastName;                                    if (other.firstName != null)
            }                                                                    return false;
                                                                         } else if (!firstName.equals(other.firstName))
            public String getFirstName() {                                   return false;
                return firstName;                                        if (lastName == null) {
            }                                                                if (other.lastName != null)
                                                                                 return false;
            public String getLastName() {                                } else if (!lastName.equals(other.lastName))
                return lastName;                                             return false;
            }                                                            return true;
                                                                     }
            @Override
            public int hashCode() {                                  @Override
                final int prime = 31;                                public String toString() {
                int result = 1;                                          return "Person(firstName:" + firstName
                result = prime * result + ((firstName == null)               + ", lastName:" + lastName + ")";
                    ? 0 : firstName.hashCode());                     }
                result = prime * result + ((lastName == null)
                    ? 0 : lastName.hashCode());                  }
                return result;
            }

            @Override
            public boolean equals(Object obj) {
                if (this == obj)
                    return true;


                                                                                                              Java
                                                                                   2011 05/28
                 Slide # 16
2011    5   28
Groovy                           :4

           @Immutable
           class Person {
               String firstName, lastName
           }




                                                      Java
                                        2011 05/28
                Slide # 17
2011   5   28
Groovy                        :4

           @Immutable
           class Person {
               String firstName, lastName
           }

           x = new Person("Junji","Uehara")
           assert x.lastName == "Uehara"
           x.firstName = "abc"
           //==>
           groovy.lang.ReadOnlyPropertyException:
           Cannot set readonly property: firstName
                                                      Java
           for class: Person             2011 05/28
                Slide # 17
2011   5   28
Groovy                           :4

           @Immutable
           class Person {
               String firstName, lastName
           }

           x = new Person("Junji","Uehara")
           assert x.lastName == "Uehara"
           x.firstName = "abc"



                                                      Java
                                        2011 05/28
                Slide # 18
2011   5   28
Groovy                           :4

           @Immutable
           class Person {
               String firstName, lastName
           }

           x = new Person("Junji","Uehara")
           assert x.lastName == "Uehara"
           x.firstName = "abc"



                                                      Java
                                        2011 05/28
                Slide # 19
2011   5   28
Groovy                           :4

           @Immutable
           class Person {
               String firstName, lastName
           }

           x = new Person("Junji","Uehara")
           assert x.lastName == "Uehara"
           x.firstName = "abc"



                                                      Java
                                        2011 05/28
                Slide # 20
2011   5   28
Java
                             2011 05/28
                Slide # 21
2011   5   28
Java
                             2011 05/28
                Slide # 21
2011   5   28
Java
                             2011 05/28
                Slide # 21
2011   5   28
Java
                             2011 05/28
                Slide # 21
2011   5   28
Java
                             2011 05/28
                Slide # 21
2011   5   28
DSL
                             OS


                                                   PHP     Haskel
                                  C++
                                                  Python
                              C                    Ruby
                                         Java


                                        Java + Groovy
                                                                          Java
                                                             2011 05/28
                Slide # 22
2011   5   28
Groovy
   Java

                                          Java
                             2011 05/28
                Slide # 23
2011   5   28

More Related Content

What's hot (20)

PDF
Kotlin Bytecode Generation and Runtime Performance
intelliyole
 
PDF
Twins: Object Oriented Programming and Functional Programming
RichardWarburton
 
PDF
Kotlin, why?
Paweł Byszewski
 
PDF
FP in Java - Project Lambda and beyond
Mario Fusco
 
PPTX
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
PDF
Java 8 Stream API. A different way to process collections.
David Gómez García
 
PPTX
Java generics final
Akshay Chaudhari
 
PDF
Java VS Python
Simone Federici
 
PDF
Refactoring to Java 8 (Devoxx BE)
Trisha Gee
 
PDF
Functional Programming in Java 8 - Exploiting Lambdas
Ganesh Samarthyam
 
PPTX
Unit testing concurrent code
Rafael Winterhalter
 
PDF
Java 8 Lambda Expressions
Scott Leberknight
 
PDF
java sockets
Enam Ahmed Shahaz
 
PDF
3. Объекты, классы и пакеты в Java
DEVTYPE
 
ODP
Ast transformations
HamletDRC
 
PPTX
Scala - where objects and functions meet
Mario Fusco
 
PDF
Important java programs(collection+file)
Alok Kumar
 
PPT
Collections Framework
Sunil OS
 
PDF
Java 7 at SoftShake 2011
julien.ponge
 
PDF
Java 7 JUG Summer Camp
julien.ponge
 
Kotlin Bytecode Generation and Runtime Performance
intelliyole
 
Twins: Object Oriented Programming and Functional Programming
RichardWarburton
 
Kotlin, why?
Paweł Byszewski
 
FP in Java - Project Lambda and beyond
Mario Fusco
 
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
Java 8 Stream API. A different way to process collections.
David Gómez García
 
Java generics final
Akshay Chaudhari
 
Java VS Python
Simone Federici
 
Refactoring to Java 8 (Devoxx BE)
Trisha Gee
 
Functional Programming in Java 8 - Exploiting Lambdas
Ganesh Samarthyam
 
Unit testing concurrent code
Rafael Winterhalter
 
Java 8 Lambda Expressions
Scott Leberknight
 
java sockets
Enam Ahmed Shahaz
 
3. Объекты, классы и пакеты в Java
DEVTYPE
 
Ast transformations
HamletDRC
 
Scala - where objects and functions meet
Mario Fusco
 
Important java programs(collection+file)
Alok Kumar
 
Collections Framework
Sunil OS
 
Java 7 at SoftShake 2011
julien.ponge
 
Java 7 JUG Summer Camp
julien.ponge
 

Viewers also liked (6)

PDF
GroovyConsole
Kiyotaka Oku
 
PPTX
Letsgo sendai nobusue_20110528
Nobuhiro Sue
 
PDF
レッツゴーデベロッパー2011「プログラミングGroovy〜G*エコシステム編」
Yasuharu Nakano
 
PDF
「プログラミングGroovy」Groovyってなんだろ?編
Kazuchika Sekiya
 
PDF
Grails 1.4.0.M1 メモLT
Tsuyoshi Yamamoto
 
PDF
スプリント計画ミーティング
Miho Nagase
 
GroovyConsole
Kiyotaka Oku
 
Letsgo sendai nobusue_20110528
Nobuhiro Sue
 
レッツゴーデベロッパー2011「プログラミングGroovy〜G*エコシステム編」
Yasuharu Nakano
 
「プログラミングGroovy」Groovyってなんだろ?編
Kazuchika Sekiya
 
Grails 1.4.0.M1 メモLT
Tsuyoshi Yamamoto
 
スプリント計画ミーティング
Miho Nagase
 
Ad

Similar to Let's go Developer 2011 sendai Let's go Java Developer (Programming Language Groovy Part) (20)

PDF
Alternate JVM Languages
Saltmarch Media
 
PPTX
Marimba - A MapReduce-based Programming Model for Self-maintainable Aggregate...
Johannes Schildgen
 
ODP
Groovy intro for OUDL
J David Beutel
 
PDF
Atlassian Groovy Plugins
Paul King
 
PDF
Scala in practice
andyrobinson8
 
PDF
Google Guava for cleaner code
Mite Mitreski
 
PPTX
Scoobi - Scala for Startups
bmlever
 
ODP
1.2 scala basics
wpgreenway
 
ODP
1.2 scala basics
futurespective
 
PDF
Write a program that asks the user for the name of a file. The progr.pdf
arri2009av
 
PDF
This program here prints the number of words that occurs in the inpu.pdf
shanki7
 
PPT
Oop lecture9 11
Shahriar Robbani
 
PDF
Breaking The Monotony
Naresh Jain
 
PDF
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
PDF
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
Publicis Sapient Engineering
 
PPTX
Marimba - Ein MapReduce-basiertes Programmiermodell für selbstwartbare Aggreg...
Johannes Schildgen
 
PDF
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Atlassian
 
PDF
Productive Programming in Groovy
Ganesh Samarthyam
 
PDF
The Groovy Way
Gabriel Dogaru
 
PDF
Sam wd programs
Soumya Behera
 
Alternate JVM Languages
Saltmarch Media
 
Marimba - A MapReduce-based Programming Model for Self-maintainable Aggregate...
Johannes Schildgen
 
Groovy intro for OUDL
J David Beutel
 
Atlassian Groovy Plugins
Paul King
 
Scala in practice
andyrobinson8
 
Google Guava for cleaner code
Mite Mitreski
 
Scoobi - Scala for Startups
bmlever
 
1.2 scala basics
wpgreenway
 
1.2 scala basics
futurespective
 
Write a program that asks the user for the name of a file. The progr.pdf
arri2009av
 
This program here prints the number of words that occurs in the inpu.pdf
shanki7
 
Oop lecture9 11
Shahriar Robbani
 
Breaking The Monotony
Naresh Jain
 
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
Publicis Sapient Engineering
 
Marimba - Ein MapReduce-basiertes Programmiermodell für selbstwartbare Aggreg...
Johannes Schildgen
 
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Atlassian
 
Productive Programming in Groovy
Ganesh Samarthyam
 
The Groovy Way
Gabriel Dogaru
 
Sam wd programs
Soumya Behera
 
Ad

More from Uehara Junji (20)

PDF
Use JWT access-token on Grails REST API
Uehara Junji
 
PDF
Groovy Bootcamp 2015 by JGGUG
Uehara Junji
 
PDF
Groovy Shell Scripting 2015
Uehara Junji
 
PDF
Shibuya JVM Groovy 20150418
Uehara Junji
 
PDF
Markup Template Engine introduced Groovy 2.3
Uehara Junji
 
PDF
Introduce Groovy 2.3 trait
Uehara Junji
 
PDF
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
Uehara Junji
 
PDF
enterprise grails challenge, 2013 Summer
Uehara Junji
 
PDF
New features of Groovy 2.0 and 2.1
Uehara Junji
 
PDF
Groovy kisobenkyoukai20130309
Uehara Junji
 
PDF
Read Groovy Compile process(Groovy Benkyoukai 2013)
Uehara Junji
 
PDF
groovy 2.1.0 20130118
Uehara Junji
 
PDF
New feature of Groovy2.0 G*Workshop
Uehara Junji
 
KEY
G* Workshop in fukuoka 20120901
Uehara Junji
 
KEY
JJUG CCC 2012 Real World Groovy/Grails
Uehara Junji
 
KEY
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Uehara Junji
 
PDF
Java x Groovy: improve your java development life
Uehara Junji
 
KEY
Jggug ws 15th LT 20110224
Uehara Junji
 
PDF
Easy Going Groovy(Groovyを気軽に使いこなそう)
Uehara Junji
 
PDF
GroovyServ concept, how to use and outline.
Uehara Junji
 
Use JWT access-token on Grails REST API
Uehara Junji
 
Groovy Bootcamp 2015 by JGGUG
Uehara Junji
 
Groovy Shell Scripting 2015
Uehara Junji
 
Shibuya JVM Groovy 20150418
Uehara Junji
 
Markup Template Engine introduced Groovy 2.3
Uehara Junji
 
Introduce Groovy 2.3 trait
Uehara Junji
 
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
Uehara Junji
 
enterprise grails challenge, 2013 Summer
Uehara Junji
 
New features of Groovy 2.0 and 2.1
Uehara Junji
 
Groovy kisobenkyoukai20130309
Uehara Junji
 
Read Groovy Compile process(Groovy Benkyoukai 2013)
Uehara Junji
 
groovy 2.1.0 20130118
Uehara Junji
 
New feature of Groovy2.0 G*Workshop
Uehara Junji
 
G* Workshop in fukuoka 20120901
Uehara Junji
 
JJUG CCC 2012 Real World Groovy/Grails
Uehara Junji
 
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Uehara Junji
 
Java x Groovy: improve your java development life
Uehara Junji
 
Jggug ws 15th LT 20110224
Uehara Junji
 
Easy Going Groovy(Groovyを気軽に使いこなそう)
Uehara Junji
 
GroovyServ concept, how to use and outline.
Uehara Junji
 

Recently uploaded (20)

PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Next level data operations using Power Automate magic
Andries den Haan
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Next level data operations using Power Automate magic
Andries den Haan
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 

Let's go Developer 2011 sendai Let's go Java Developer (Programming Language Groovy Part)

  • 1. Groovy Java 2011 5 28
  • 2. Java 2011 05/28 Slide # 2 2011 5 28
  • 3. Java 2011 05/28 Slide # 3 2011 5 28
  • 4. $ cat input.txt That that is is that that is not is not is that it it is $ java WordCount input.txt 1: [That] 2: [not] 2: [it] 4: [that] 6: [is] Java 2011 05/28 Slide # 4 2011 5 28
  • 5. Java WordCount:48      Set<Map.Entry<String, Integer>> entrySet = import java.util.Comparator; map.entrySet(); import java.util.HashMap;      Object[] list = entrySet.toArray(); import java.util.Map;     Comparator comp = new Comparator(){ import java.util.Set;        public int compare(Object o1, Object o2) import java.util.List; { import java.util.Arrays;          Map.Entry<String, Integer> e1 = import java.io.FileReader; (Map.Entry<String, Integer>) o1; import java.io.BufferedReader;          Map.Entry<String, Integer> e2 = import java.io.FileNotFoundException; (Map.Entry<String, Integer>) o2; import java.io.IOException;         return e1.getValue() - e2.getValue();         } public class WordCount {       };   @SuppressWarnings(value = "unchecked")       Arrays.sort(list, comp);   public static void main(String[] args) {       for (Object it: list) {     FileReader fis = null;         Map.Entry<String, Integer> entry =     BufferedReader br = null; (Map.Entry<String, Integer>)it;     try {         System.out.println(entry.getValue() + ":       HashMap<String, Integer> map = new ["+entry.getKey()+"]"); HashMap<String, Integer>();       }       fis = new FileReader(args[0]);     }       br = new BufferedReader(fis);     catch (IOException e) {       String line;       try {if (br != null) br.close();}catch       while ((line = br.readLine()) != null) { (IOException ioe){}         for (String it: line.split("s+")) {       try {if (fis != null)fis.close();}catch          map.put(it, (map.get(it)==null) ? 1 : (IOException ioe){} (map.get(it) + 1));       e.printStackTrace();         }     } Java       }   } } 2011 05/28 Slide # 5 2011 5 28
  • 6. Groovy WordCount(9 ) def map = [:].withDefault{0} new File(args[0]).eachLine {   it.split(/s+/).each {     map[it]++    } } map.entrySet().sort{it.value}.each {   println "${it.value}: [${it.key}]" } Java 2011 05/28 Slide # 6 2011 5 28
  • 7. Java             Set<Map.Entry<String, Integer>> import java.util.Comparator; entrySet = map.entrySet(); import java.util.HashMap;             Object[] list = entrySet.toArray(); import java.util.Map;             Comparator comp = new Comparator(){ import java.util.Set;                 public int compare(Object o1, import java.util.List; Object o2) { import java.util.Arrays;                     Map.Entry<String, Integer> e1 import java.io.FileReader; = (Map.Entry<String, Integer>) o1; import java.io.BufferedReader;                     Map.Entry<String, Integer> e2 import java.io.FileNotFoundException; = (Map.Entry<String, Integer>) o2; import java.io.IOException;                     return e1.getValue() - e2.getValue(); public class WordCount {                 }     @SuppressWarnings(value = "unchecked")             };     public static void main(String[] args) {             Arrays.sort(list, comp);         FileReader fis = null;             for (Object it: list) {         BufferedReader br = null;                 Map.Entry<String, Integer> entry         try { = (Map.Entry<String, Integer>)it;             HashMap<String, Integer> map = new                 System.out.println(entry.getValue HashMap<String, Integer>(); () + ": ["+entry.getKey()+"]");             fis = new FileReader(args[0]);             }             br = new BufferedReader(fis);         }             String line;         catch (IOException e) {             while ((line = br.readLine()) !=             try {if (br != null) br.close();} null) { catch(IOException ioe){}                 for (String it: line.split("s             try {if (fis != null)fis.close();} +")) { catch(IOException ioe){}                     map.put(it, (map.get(it)             e.printStackTrace(); ==null) ? 1 : (map.get(it) + 1));                 }         }     } Java             } } 2011 05/28 Slide # 7 2011 5 28
  • 8. Groovy WordCount(9 ) def map = [:].withDefault{0} // value 0 map new File(args[0]).eachLine { //   it.split(/s+/).each {     // /s+/     map[it]++                // map 1   } } map.entrySet().sort{it.value}.each {// map entrySet value   println "${it.value}: [${it.key}]"// key,value } Java 2011 05/28 Slide # 8 2011 5 28
  • 9. Groovy WordCount(9 ) def map = [:].withDefault{0} // value 0 map new File(args[0]).eachLine { //   it.split(/s+/).each {     // /s+/     map[it]++                // map 1   } } map.entrySet().sort{it.value}.each {// map entrySet value   println "${it.value}: [${it.key}]"// key,value } Java 2011 05/28 Slide # 9 2011 5 28
  • 10. Groovy WordCount(9 ) def map = [:].withDefault{0} // value 0 map new File(args[0]).eachLine { //   it.split(/s+/).each {     // /s+/     map[it]++                // map 1   } } map.entrySet().sort{it.value}.each {// map entrySet value   println "${it.value}: [${it.key}]"// key,value } Java 2011 05/28 Slide # 10 2011 5 28
  • 11. Groovy WordCount(9 ) def map = [:].withDefault{0} // value 0 map new File(args[0]).eachLine { //   it.split(/s+/).each {     // /s+/     map[it]++                // map 1   } } map.entrySet().sort{it.value}.each {// map entrySet value   println "${it.value}: [${it.key}]"// key,value } Java 2011 05/28 Slide # 11 2011 5 28
  • 12. Groovy WordCount(9 ) def map = [:].withDefault{0} // value 0 map new File(args[0]).eachLine { //   it.split(/s+/).each {     // /s+/     map[it]++                // map 1   } } map.entrySet().sort{it.value}.each {// map entrySet value   println "${it.value}: [${it.key}]"// key,value } Java 2011 05/28 Slide # 12 2011 5 28
  • 13. Groovy WordCount(9 ) def map = [:].withDefault{0} // value 0 map new File(args[0]).eachLine { //   it.split(/s+/).each {     // /s+/     map[it]++                // map 1   } } map.entrySet().sort{it.value}.each {// map entrySet value   println "${it.value}: [${it.key}]"// key,value } Java 2011 05/28 Slide # 13 2011 5 28
  • 14. Groovy WordCount(9 ) def map = [:].withDefault{0} // value 0 map new File(args[0]).eachLine { //   it.split(/s+/).each {     // /s+/     map[it]++                // map 1   } } map.entrySet().sort{it.value}.each {// map entrySet value   println "${it.value}: [${it.key}]"// key,value } Java 2011 05/28 Slide # 14 2011 5 28
  • 15. Java 2011 05/28 Slide # 15 2011 5 28
  • 16. public final class Person { if (obj == null) private final String firstName; return false; private final String lastName; if (getClass() != obj.getClass()) return false; public Person(String firstName, String lastName) { Person other = (Person) obj; this.firstName = firstName; if (firstName == null) { this.lastName = lastName; if (other.firstName != null) } return false; } else if (!firstName.equals(other.firstName)) public String getFirstName() { return false; return firstName; if (lastName == null) { } if (other.lastName != null) return false; public String getLastName() { } else if (!lastName.equals(other.lastName)) return lastName; return false; } return true; } @Override public int hashCode() { @Override final int prime = 31; public String toString() { int result = 1; return "Person(firstName:" + firstName result = prime * result + ((firstName == null) + ", lastName:" + lastName + ")"; ? 0 : firstName.hashCode()); } result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); } return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; Java 2011 05/28 Slide # 16 2011 5 28
  • 17. public final class Person { if (obj == null) private final String firstName; return false; private final String lastName; if (getClass() != obj.getClass()) return false; public Person(String firstName, String lastName) { Person other = (Person) obj; this.firstName = firstName; if (firstName == null) { this.lastName = lastName; if (other.firstName != null) } return false; } else if (!firstName.equals(other.firstName)) public String getFirstName() { return false; return firstName; if (lastName == null) { } if (other.lastName != null) return false; public String getLastName() { } else if (!lastName.equals(other.lastName)) return lastName; return false; } return true; } @Override public int hashCode() { @Override final int prime = 31; public String toString() { int result = 1; return "Person(firstName:" + firstName result = prime * result + ((firstName == null) + ", lastName:" + lastName + ")"; ? 0 : firstName.hashCode()); } result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); } return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; Java 2011 05/28 Slide # 16 2011 5 28
  • 18. Groovy :4 @Immutable class Person { String firstName, lastName } Java 2011 05/28 Slide # 17 2011 5 28
  • 19. Groovy :4 @Immutable class Person { String firstName, lastName } x = new Person("Junji","Uehara") assert x.lastName == "Uehara" x.firstName = "abc" //==> groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: firstName Java for class: Person 2011 05/28 Slide # 17 2011 5 28
  • 20. Groovy :4 @Immutable class Person { String firstName, lastName } x = new Person("Junji","Uehara") assert x.lastName == "Uehara" x.firstName = "abc" Java 2011 05/28 Slide # 18 2011 5 28
  • 21. Groovy :4 @Immutable class Person { String firstName, lastName } x = new Person("Junji","Uehara") assert x.lastName == "Uehara" x.firstName = "abc" Java 2011 05/28 Slide # 19 2011 5 28
  • 22. Groovy :4 @Immutable class Person { String firstName, lastName } x = new Person("Junji","Uehara") assert x.lastName == "Uehara" x.firstName = "abc" Java 2011 05/28 Slide # 20 2011 5 28
  • 23. Java 2011 05/28 Slide # 21 2011 5 28
  • 24. Java 2011 05/28 Slide # 21 2011 5 28
  • 25. Java 2011 05/28 Slide # 21 2011 5 28
  • 26. Java 2011 05/28 Slide # 21 2011 5 28
  • 27. Java 2011 05/28 Slide # 21 2011 5 28
  • 28. DSL OS PHP Haskel C++ Python C Ruby Java Java + Groovy Java 2011 05/28 Slide # 22 2011 5 28
  • 29. Groovy Java Java 2011 05/28 Slide # 23 2011 5 28