11
Introduction to 12/13/2011 1 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

Embed Size (px)

Citation preview

Page 1: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

1

Introduction to

12/13/2011

Prepared by:Vincent Schwarzer, Chih-Hung Hsieh

Java Enterprise Application Development

Page 2: Introduction to 12/13/20111 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

Page 3: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

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

Page 4: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

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

Page 5: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

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

Page 6: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

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

Page 7: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

712/13/2011 Java Enterprise Application Development

Groovy Builder

one use for builders is the generation of markup:

Page 8: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

812/13/2011 Java Enterprise Application Development

Groovy Builder

Result:

Page 9: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

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)

Page 10: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

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

Page 11: Introduction to 12/13/20111 Prepared by: Vincent Schwarzer, Chih-Hung Hsieh Java Enterprise Application Development

1112/13/2011 Java Enterprise Application Development

Thank You