Groovy Intro
Upcoming SlideShare
Loading in...5
×
 

Groovy Intro

on

  • 809 views

 

Statistics

Views

Total Views
809
Views on SlideShare
809
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Introduce wiki page
  • Introduce wiki page
  • Introduce wiki page
  • Introduce wiki page

Groovy Intro Groovy Intro Presentation Transcript

  • Groovy: Fly Beyond Java Copyright © 2001-2008 Infor Global Solutions
  • Agenda
    • Why Groovy Appears
    • How Groovy Rocks
    • 什 么是 好 的程序语言?
  • CEO 的梦想 =
  • 程序员的梦想 写程序 泡网 午饭 和美眉网聊 打游戏 下班
  • Copyright © 2001-2006 Infor Global Solutions 哪种编程语言更“好”? 义 義 好 的编程语言也许应该更像是一门 “ 语言 ”
  • 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