Upload
roland-barker
View
215
Download
2
Embed Size (px)
Citation preview
1
Introduction to
12/13/2011
Prepared by:Vincent Schwarzer, Chih-Hung Hsieh
Java Enterprise Application Development
212/13/2011 Java Enterprise Application Development
Structure
1. The history of Groovy
2. What is Groovy?Features & Strengths
4. Groovy vs. Java OOP
3. Groovy Builder
5. Common use cases
6. Short example
312/13/2011 Java Enterprise Application Development
The history of Groovy
Several versions released between 2004 and 2006
James Strachan started developing Groovy in 2003
Released final version called Groovy 1.0 in 2007
412/13/2011 Java Enterprise Application Development
What is Groovy?
• An agile and dynamic language for the JVM
• Builds upon the strength of Java
Additional power features inspired by languageslike Ruby, Python and SmallTalk
• Almost zero learning curve for Java Developers
• Seamlessly integrates with all existing Java classes and libraries• You can use it anywhere you can use Java
512/13/2011 Java Enterprise Application Development
Features & Strengths
// old school Java code, but also valid Groovy codeSystem.out.println("Hello, world!");
// idiomatic Groovyprintln "Hello, world!"
// dynamic variable definitiondef name = “Peter"
// GString featuring string interpolationprintln "Hello, $name" // => "Hello, Peter"
// statically typed variableString songName = "Coding in the Name of"
println "Now playing - $songName"
String multiline = """this is a multilinestring. There is not need to embednewline characters in it"""
println multiline
612/13/2011 Java Enterprise Application Development
Features & Strengths
// method definitiondef greet(name) { println "Hello, $name!"}
// method invocationgreet “Peter"greet(“Peter“)
// a list def beers = [“Becks", “Corona", “Budweiser", “Heineken"]
// list access println "My favourite beer is ${beers[1]}“for (i in beers) { println i }
// imports can appear anywhere and support the creation of aliases import static java.util.Calendar.getInstance as now import java.sql.Date as SDate
712/13/2011 Java Enterprise Application Development
Groovy Builder
one use for builders is the generation of markup:
812/13/2011 Java Enterprise Application Development
Groovy Builder
Result:
912/13/2011 Java Enterprise Application Development
Groovy vs. Java
Similar capabilities to Java:
Define classes, interfaces, enums, annotations
Differences to Java:
Classes (and interfaces etc.) public by default Methods public by default Property support within classes (auto-setters/getters)
1012/13/2011 Java Enterprise Application Development
Common use cases
Web application development
scripting
Rapid prototyping
As a proof on concept
Exploratory Programming
Test class / method capabilities
1112/13/2011 Java Enterprise Application Development
Thank You