Professional Documents
Culture Documents
Why?
Java Jobs
© 2008 BearingPoint, Inc. 4
Groovy
Java EE Jobs
© 2008 BearingPoint, Inc. 5
Groovy
JSR 241
GroovyBeans
class GroovyBean {
String name
}
Autoboxing
def b = new GroovyBean()
b.name = “groovy bean“
Duck Typing
„When I see a bird that walks like a
duck and swims like a duck and
quacks like a duck, I call that bird a
duck.“
Poem by James Whitcomb Riley
Expressiveness
Java:
java.net.URLEncoder.encode(“a b“);
Groovy:
URLEncoder.encode ‘a b‘
GStrings
Lists
def aList = []
Maps
def emptyMap = [:]
Maps
myMap.name == “Max“
myMap[“age“] == “33“
Regular Expressions
“cheesecheese“ =~ “cheese“
“cheesecheese“ =~ /cheese/
Loops
for (int i=0;i<6;i++) {}
for (i in 0..9) {}
10.times {}
Closures
def myClosure = {
/* do something */
}
[3,1,2].each {
print “value:“+it
}
Builders
def xml = new groovy.xml.MarkupBuilder()
xml.authors {
author(name:‘Stephen King‘) {
book(title:‘The Shining‘)
book(title:‘The Stand‘)
}
author(name:‘James Patterson‘) {
book(title:‘Along Came a Spider‘)
}
}
Builders
<authors>
<author name=“Stephen King“>
<book title=“The Shining“ />
<book title=“The Stand“ />
</author>
<author name=“James Patterson“>
<book title=“Along Came a Spider“ />
<author>
<authors>
if (myString) myMethod(myString)
Save Dereferencing
Long id=null;
if (session.getAttribute(“user“) != null) {
id = ((User) session.getAttribute(“user“)).getId();
}
def id = session.user?.id
IDE Integration
Java:
public class RecursiveFileReading {
Groovy:
groovy -e “new File(‘.‘).eachFileRecurse { println it }“
RESTfull
Representational State Transfer
GET
POST
PUT
DELETE
HEAD
OPTIONS
RESTfull
http://localhost:8080/application/user/profile/123
Controller Action ID
DRY Paradigm
(Don‘t Repeat Yourself)
Components
Grails
Java EE
YUI GWT
Plugin API
JSF
Struts
JMS
ACEGI/Spring Security, JSecurity
OpenID
Functional Testing (Canoo WebTest)
Apache Axis 2, XFire
GORM
Groovy Object-Relational Mapping
GORM
class Book {
String title
}
GORM
class Book {String author
String title
Date releaseDate
static constraints = {
author(blank:false, size:2..30)
releaseDate(nullable: true) }
}
}
}
GORM
book.author = “author A“
book.title = “title 1“
book.save()
GORM
def book = new Book()
book.author = “author A“
book.title = “title 1“
if (book.save()) {
/* successfull flow */
} else {
/* error flow */
}
(Dynamic) Finders
def macBook = Book.get(1)
Scaffolding
Dynamic Scaffolding
Static Scaffolding
Success Stories?
http://groovy.codehaus.org/
http://www.grails.org