ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Groovy: Fly Beyond Java Copyright ? 2001-2008 Infor Global Solutions
Agenda Why Groovy Appears How Groovy Rocks
ʲ ôÊÇ ºÃ µÄ³ÌÐòÓïÑÔ£¿
CEO µÄÃÎÏë =
³ÌÐòÔ±µÄÃÎÏë д³ÌÐò ÅÝÍø Îç·¹ ºÍÃÀüÍøÁÄ ´òÓÎÏ· Ï°à
Copyright ? 2001-2006 Infor Global Solutions ÄÄÖÖ±à³ÌÓïÑÔ¸ü¡°ºÃ¡±£¿ Òå Áx ºÃ µÄ±à³ÌÓïÑÔÒ²ÐíÓ¦¸Ã¸üÏñÊÇÒ»ÃÅ ¡° ÓïÑÔ ¡±
Copyright ? 2001-2006 Infor Global Solutions ÓÚÊÇ Groovy µ®ÉúÁË Groovy ʹµÃ Java ¸ü¡° ÓïÑÔ ¡± Java µÄ Ç¿´ó¼¼Êõ Àà Ruby µÈ¶¯Ì¬ÓïÑÔ µÄÇáÓ¯Óï·¨ Groovy
Copyright ? 2001-2006 Infor Global Solutions »¶Ó­À´µ½¼ò½àÃÀÃîµÄ Groovy ÊÀ½ç
Copyright ? 2001-2006 Infor Global Solutions ±ðÔÚºõÀàÐÍ Java: String name = ¡°abc¡±; Groovy: String name = ¡°abc¡± def  name name = ¡°abc¡±
Copyright ? 2001-2006 Infor Global Solutions ¡° Ö±½Ó¡±·ÃÎÊÊôÐÔ class Person { private String name; public Person(String name) {this.name = name;} public String getName() {return name;} } Person person = new person(¡°ocean¡±) return person.getName(); class Person { String name; } Person person = new Person(name:¡±ocean¡±) return person .name
Copyright ? 2001-2006 Infor Global Solutions Á˲»ÆðµÄ×Ö·û´® firstName = ¡°ocean¡± lastName = ¡°dong¡± message = ¡°My name is  $ firstName  $ lastName¡± person = new Person() person.setName(¡°ocean¡±) message = ¡°My name is  ${ person.name } ¡± Message =  ¡° ¡°¡° Hi, My name is ${person.name} ¡±¡±¡± def pattern =  / hello.* /
Copyright ? 2001-2006 Infor Global Solutions ¼¯ºÏ£º¼òµ¥ÀàÐͶøÒÑ List: def aList = [1, 2, 3] def aList = [10, ¡°abc¡±, new Date()] Map: def aMap = [a:1, b:2] Range: def aRange = ¡®a¡¯..¡¯z¡¯ def numbers = 0..<10
Copyright ? 2001-2006 Infor Global Solutions ¿É°®µÄ²Ù×÷·û [1, 2, 3]  <<  4 def aMap = [a:1, b:2] println aMap . a println aMap [ a ] ¡° hello world¡±  =~  /hello.*/ println person ? .wife ? .name
Copyright ? 2001-2006 Infor Global Solutions ÍòÎï½Ô¿ÉÅÐ¶Ï If(1) assert 1 def aList = [1, 2, 3] If(aList) assert aList def person If(person) assert !person
Copyright ? 2001-2006 Infor Global Solutions ËÄͨ°Ë´ïµÄ Switch switch(10) { case 0: case 0..9: case [8,9,11]: case Float: case {it % 3 == 0}: case ~/../: default: }
Copyright ? 2001-2006 Infor Global Solutions ͸Ã÷µÄ¼¯ºÏ ArrayList names = new ArrayList() for(Person person : persons) { names.add(person.getName()); } return names; def persons = [new Person(¡±ocean¡±), new Person(¡±coco¡±)] assert persons .name  == [¡°ocean¡±, ¡°coco¡±] assert persons *.getGender()  == [¡°Male¡±, ¡°Female¡±]
Copyright ? 2001-2006 Infor Global Solutions Closure:  ÖÕ¼«´úÂëÖØÓà ArrayList persons = ¡­ for(Person person : persons) { System.out.println(person.getName()); } persons.each  {it ->  println it.name }
Copyright ? 2001-2006 Infor Global Solutions Ô¶Ô¶²»Ö¹ÕâЩŶ¡£¡£¡£ Builder Meta Programming Groovylet GSP GRails Scriptom Griffon GMaven Gant GSQL GORM Tellurium http://groovy.codehaus.org/
Thanks

More Related Content

Groovy Intro

  • 1. Groovy: Fly Beyond Java Copyright ? 2001-2008 Infor Global Solutions
  • 2. Agenda Why Groovy Appears How Groovy Rocks
  • 3. ʲ ôÊÇ ºÃ µÄ³ÌÐòÓïÑÔ£¿
  • 5. ³ÌÐòÔ±µÄÃÎÏë д³ÌÐò ÅÝÍø Îç·¹ ºÍÃÀüÍøÁÄ ´òÓÎÏ· Ï°à
  • 6. Copyright ? 2001-2006 Infor Global Solutions ÄÄÖÖ±à³ÌÓïÑÔ¸ü¡°ºÃ¡±£¿ Òå Áx ºÃ µÄ±à³ÌÓïÑÔÒ²ÐíÓ¦¸Ã¸üÏñÊÇÒ»ÃÅ ¡° ÓïÑÔ ¡±
  • 7. Copyright ? 2001-2006 Infor Global Solutions ÓÚÊÇ Groovy µ®ÉúÁË Groovy ʹµÃ Java ¸ü¡° ÓïÑÔ ¡± Java µÄ Ç¿´ó¼¼Êõ Àà Ruby µÈ¶¯Ì¬ÓïÑÔ µÄÇáÓ¯Óï·¨ Groovy
  • 8. Copyright ? 2001-2006 Infor Global Solutions »¶Ó­À´µ½¼ò½àÃÀÃîµÄ Groovy ÊÀ½ç
  • 9. Copyright ? 2001-2006 Infor Global Solutions ±ðÔÚºõÀàÐÍ Java: String name = ¡°abc¡±; Groovy: String name = ¡°abc¡± def name name = ¡°abc¡±
  • 10. Copyright ? 2001-2006 Infor Global Solutions ¡° Ö±½Ó¡±·ÃÎÊÊôÐÔ class Person { private String name; public Person(String name) {this.name = name;} public String getName() {return name;} } Person person = new person(¡°ocean¡±) return person.getName(); class Person { String name; } Person person = new Person(name:¡±ocean¡±) return person .name
  • 11. Copyright ? 2001-2006 Infor Global Solutions Á˲»ÆðµÄ×Ö·û´® firstName = ¡°ocean¡± lastName = ¡°dong¡± message = ¡°My name is $ firstName $ lastName¡± person = new Person() person.setName(¡°ocean¡±) message = ¡°My name is ${ person.name } ¡± Message = ¡° ¡°¡° Hi, My name is ${person.name} ¡±¡±¡± def pattern = / hello.* /
  • 12. Copyright ? 2001-2006 Infor Global Solutions ¼¯ºÏ£º¼òµ¥ÀàÐͶøÒÑ List: def aList = [1, 2, 3] def aList = [10, ¡°abc¡±, new Date()] Map: def aMap = [a:1, b:2] Range: def aRange = ¡®a¡¯..¡¯z¡¯ def numbers = 0..<10
  • 13. Copyright ? 2001-2006 Infor Global Solutions ¿É°®µÄ²Ù×÷·û [1, 2, 3] << 4 def aMap = [a:1, b:2] println aMap . a println aMap [ a ] ¡° hello world¡± =~ /hello.*/ println person ? .wife ? .name
  • 14. Copyright ? 2001-2006 Infor Global Solutions ÍòÎï½Ô¿ÉÅÐ¶Ï If(1) assert 1 def aList = [1, 2, 3] If(aList) assert aList def person If(person) assert !person
  • 15. Copyright ? 2001-2006 Infor Global Solutions ËÄͨ°Ë´ïµÄ Switch switch(10) { case 0: case 0..9: case [8,9,11]: case Float: case {it % 3 == 0}: case ~/../: default: }
  • 16. Copyright ? 2001-2006 Infor Global Solutions ͸Ã÷µÄ¼¯ºÏ ArrayList names = new ArrayList() for(Person person : persons) { names.add(person.getName()); } return names; def persons = [new Person(¡±ocean¡±), new Person(¡±coco¡±)] assert persons .name == [¡°ocean¡±, ¡°coco¡±] assert persons *.getGender() == [¡°Male¡±, ¡°Female¡±]
  • 17. Copyright ? 2001-2006 Infor Global Solutions Closure: ÖÕ¼«´úÂëÖØÓà ArrayList persons = ¡­ for(Person person : persons) { System.out.println(person.getName()); } persons.each {it -> println it.name }
  • 18. Copyright ? 2001-2006 Infor Global Solutions Ô¶Ô¶²»Ö¹ÕâЩŶ¡£¡£¡£ Builder Meta Programming Groovylet GSP GRails Scriptom Griffon GMaven Gant GSQL GORM Tellurium http://groovy.codehaus.org/

Editor's Notes

  • #3: Introduce wiki page
  • #4: Introduce wiki page
  • #5: Introduce wiki page
  • #6: Introduce wiki page