Suche senden
Hochladen
Eclipsecon09 Introduction To Groovy
•
4 gefällt mir
•
3,967 views
Andres Almiray
Folgen
Eclipsecon09 Introduction to Groovy
Weniger lesen
Mehr lesen
Technologie
Unterhaltung & Humor
Melden
Teilen
Melden
Teilen
1 von 54
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
TDC2016SP - Trilha .NET
TDC2016SP - Trilha .NET
tdc-globalcode
Expression trees in c#
Expression trees in c#
Oleksii Holub
Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)
Alina Vilk
A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014
Damien Seguy
Ontopia tutorial
Ontopia tutorial
Lars Marius Garshol
Ruby 程式語言簡介
Ruby 程式語言簡介
Wen-Tien Chang
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
Wen-Tien Chang
Introduction to Functional Programming
Introduction to Functional Programming
Hoàng Lâm Huỳnh
Empfohlen
TDC2016SP - Trilha .NET
TDC2016SP - Trilha .NET
tdc-globalcode
Expression trees in c#
Expression trees in c#
Oleksii Holub
Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)
Alina Vilk
A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014
Damien Seguy
Ontopia tutorial
Ontopia tutorial
Lars Marius Garshol
Ruby 程式語言簡介
Ruby 程式語言簡介
Wen-Tien Chang
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
Wen-Tien Chang
Introduction to Functional Programming
Introduction to Functional Programming
Hoàng Lâm Huỳnh
Groovy for Java Developers
Groovy for Java Developers
Andres Almiray
Introduction to Oracle Groovy
Introduction to Oracle Groovy
Deepak Bhagat
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
Andres Almiray
Introduction To Groovy
Introduction To Groovy
manishkp84
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Tsuyoshi Yamamoto
Presentatie - Introductie in Groovy
Presentatie - Introductie in Groovy
Getting value from IoT, Integration and Data Analytics
GeeCON Prague 2014 - Metaprogramming with Groovy
GeeCON Prague 2014 - Metaprogramming with Groovy
Iván López Martín
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
James Williams
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres Almiray
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
Tsuyoshi Yamamoto
Session inaugurale du Groovy User Group Paris
Session inaugurale du Groovy User Group Paris
Guillaume Laforge
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
Iván López Martín
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
tdc-globalcode
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Guillaume Laforge
Groovy for java developers
Groovy for java developers
Puneet Behl
Groovy!
Groovy!
Petr Giecek
Groovy And Grails JUG Sardegna
Groovy And Grails JUG Sardegna
John Leach
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
Andres Almiray
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
Kostas Saidis
Corinna-2023.pptx
Corinna-2023.pptx
Curtis Poe
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Andres Almiray
Liberando a produccion con confianza
Liberando a produccion con confianza
Andres Almiray
Weitere ähnliche Inhalte
Ähnlich wie Eclipsecon09 Introduction To Groovy
Groovy for Java Developers
Groovy for Java Developers
Andres Almiray
Introduction to Oracle Groovy
Introduction to Oracle Groovy
Deepak Bhagat
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
Andres Almiray
Introduction To Groovy
Introduction To Groovy
manishkp84
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Tsuyoshi Yamamoto
Presentatie - Introductie in Groovy
Presentatie - Introductie in Groovy
Getting value from IoT, Integration and Data Analytics
GeeCON Prague 2014 - Metaprogramming with Groovy
GeeCON Prague 2014 - Metaprogramming with Groovy
Iván López Martín
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
James Williams
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres Almiray
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
Tsuyoshi Yamamoto
Session inaugurale du Groovy User Group Paris
Session inaugurale du Groovy User Group Paris
Guillaume Laforge
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
Iván López Martín
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
tdc-globalcode
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Guillaume Laforge
Groovy for java developers
Groovy for java developers
Puneet Behl
Groovy!
Groovy!
Petr Giecek
Groovy And Grails JUG Sardegna
Groovy And Grails JUG Sardegna
John Leach
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
Andres Almiray
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
Kostas Saidis
Corinna-2023.pptx
Corinna-2023.pptx
Curtis Poe
Ähnlich wie Eclipsecon09 Introduction To Groovy
(20)
Groovy for Java Developers
Groovy for Java Developers
Introduction to Oracle Groovy
Introduction to Oracle Groovy
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
Introduction To Groovy
Introduction To Groovy
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Presentatie - Introductie in Groovy
Presentatie - Introductie in Groovy
GeeCON Prague 2014 - Metaprogramming with Groovy
GeeCON Prague 2014 - Metaprogramming with Groovy
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
Session inaugurale du Groovy User Group Paris
Session inaugurale du Groovy User Group Paris
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy for java developers
Groovy for java developers
Groovy!
Groovy!
Groovy And Grails JUG Sardegna
Groovy And Grails JUG Sardegna
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
Corinna-2023.pptx
Corinna-2023.pptx
Mehr von Andres Almiray
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Andres Almiray
Liberando a produccion con confianza
Liberando a produccion con confianza
Andres Almiray
Liberando a produccion con confidencia
Liberando a produccion con confidencia
Andres Almiray
OracleDB Ecosystem for Java Developers
OracleDB Ecosystem for Java Developers
Andres Almiray
Softcon.ph - Maven Puzzlers
Softcon.ph - Maven Puzzlers
Andres Almiray
Maven Puzzlers
Maven Puzzlers
Andres Almiray
Oracle Database Ecosystem for Java Developers
Oracle Database Ecosystem for Java Developers
Andres Almiray
JReleaser - Releasing at the speed of light
JReleaser - Releasing at the speed of light
Andres Almiray
Building modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and Layrry
Andres Almiray
Going Reactive with g rpc
Going Reactive with g rpc
Andres Almiray
Building modular applications with JPMS and Layrry
Building modular applications with JPMS and Layrry
Andres Almiray
Taking Micronaut out for a spin
Taking Micronaut out for a spin
Andres Almiray
Apache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and You
Andres Almiray
What I wish I knew about Maven years ago
What I wish I knew about Maven years ago
Andres Almiray
What I wish I knew about maven years ago
What I wish I knew about maven years ago
Andres Almiray
The impact of sci fi in tech
The impact of sci fi in tech
Andres Almiray
Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019
Andres Almiray
Creating Better Builds with Gradle
Creating Better Builds with Gradle
Andres Almiray
Interacting with the Oracle Cloud Java SDK with Gradle
Interacting with the Oracle Cloud Java SDK with Gradle
Andres Almiray
Gradle ex-machina
Gradle ex-machina
Andres Almiray
Mehr von Andres Almiray
(20)
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Liberando a produccion con confianza
Liberando a produccion con confianza
Liberando a produccion con confidencia
Liberando a produccion con confidencia
OracleDB Ecosystem for Java Developers
OracleDB Ecosystem for Java Developers
Softcon.ph - Maven Puzzlers
Softcon.ph - Maven Puzzlers
Maven Puzzlers
Maven Puzzlers
Oracle Database Ecosystem for Java Developers
Oracle Database Ecosystem for Java Developers
JReleaser - Releasing at the speed of light
JReleaser - Releasing at the speed of light
Building modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and Layrry
Going Reactive with g rpc
Going Reactive with g rpc
Building modular applications with JPMS and Layrry
Building modular applications with JPMS and Layrry
Taking Micronaut out for a spin
Taking Micronaut out for a spin
Apache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and You
What I wish I knew about Maven years ago
What I wish I knew about Maven years ago
What I wish I knew about maven years ago
What I wish I knew about maven years ago
The impact of sci fi in tech
The impact of sci fi in tech
Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019
Creating Better Builds with Gradle
Creating Better Builds with Gradle
Interacting with the Oracle Cloud Java SDK with Gradle
Interacting with the Oracle Cloud Java SDK with Gradle
Gradle ex-machina
Gradle ex-machina
Kürzlich hochgeladen
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
soniya singh
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
Allon Mureinik
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Pixlogix Infotech
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Rafal Los
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
naman860154
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Delhi Call girls
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Delhi Call girls
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
gurkirankumar98700
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
Pooja Nehwal
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Principled Technologies
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
HostedbyConfluent
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Sinan KOZAK
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Delhi Call girls
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Igalia
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
The Digital Insurer
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Puma Security, LLC
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
ThousandEyes
Kürzlich hochgeladen
(20)
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Eclipsecon09 Introduction To Groovy
1.
Introduction to Groovy ©
2009 by «Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
2.
Agenda
• What is Groovy • From Java to Groovy • Java-like features • Not-Java features • Unique features • Eclipse & Groovy Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 2
3.
What is Groovy? ©
2009 by «Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
4.
http://www.flickr.com/photos/teagrrl/78941282/
Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 4
5.
From Java to
Groovy © 2009 by «Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
6.
HelloWorld in Java
public class HelloWorld { String name; public void setName(String name) { this.name = name; } public String getName(){ return name; } public String greet() { return quot;Hello quot;+ name; } public static void main(String args[]){ HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(quot;Groovyquot;); System.out.println( helloWorld.greet() ); } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 6
7.
HelloWorld in Groovy
public class HelloWorld { String name; public void setName(String name) { this.name = name; } public String getName(){ return name; } public String greet() { return quot;Hello quot;+ name; } public static void main(String args[]){ HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(quot;Groovyquot;); System.out.println( helloWorld.greet() ); } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 7
8.
Step 1: Let’s
get rid of the noise public class HelloWorld { String name; public void setName(String name) { this.name = name; } public String getName(){ return name; } public String greet() { return quot;Hello quot;+ name; } public static void main(String args[]){ HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(quot;Groovyquot;); System.out.println( helloWorld.greet() ); } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 8
9.
Step 1 -
Results class HelloWorld { String name void setName(String name) { this.name = name } String getName(){ return name } String greet() { return quot;Hello quot;+ name } static void main(String args[]){ HelloWorld helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) System.out.println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 9
10.
Step 2: let’s
get rid of boilerplate class HelloWorld { String name void setName(String name) { this.name = name } String getName(){ return name } String greet() { return quot;Hello quot;+ name } static void main(String args[]){ args[] HelloWorld helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) System.out.println( helloWorld.greet() ) System.out. } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 10
11.
Step 2 -
Results class HelloWorld { String name String greet() { return quot;Hello quot;+ name } static void main( args ){ HelloWorld helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 11
12.
Step 3: Introduce
dynamic types class HelloWorld { String name String greet() { return quot;Hello quot;+ name } static void main( args ){ HelloWorld helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 12
13.
Step 3 -
Results class HelloWorld { String name def greet() { return quot;Hello quot;+ name } static def main( args ){ def helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 13
14.
Step 4: Use
variable interpolation class HelloWorld { String name def greet(){ return quot;Hello quot;+ name } static def main( args ){ def helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 14
15.
Step 4 -
Results class HelloWorld { String name def greet(){ return quot;Hello ${name}quot; } static def main( args ){ def helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 15
16.
Step 5: Let’s
get rid of more keywords class HelloWorld { String name def greet(){ return quot;Hello ${name}quot; } static def main( args ){ def helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 16
17.
Step 5 -
Results class HelloWorld { String name def greet(){ quot;Hello ${name}quot; } static main( args ){ def helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 17
18.
Step 6: POJOs
on steroids class HelloWorld { String name def greet(){ quot;Hello ${name}quot; } static main( args ){ def helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 18
19.
Step 6 -
Results class HelloWorld { String name def greet(){ quot;Hello ${name}quot; } static main( args ){ def helloWorld = new HelloWorld(name:quot;Groovyquot;) // helloWorld.setName(quot;Groovyquot;) // helloWorld.name = quot;Groovyquot; // helloWorld[quot;namequot;] = quot;Groovyquot; println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 19
20.
Step 7: Groovy
supports scripts class HelloWorld { String name def greet(){ quot;Hello ${name}quot; } static main( args ){ def helloWorld = new HelloWorld(name:quot;Groovyquot;) println helloWorld.greet() } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 20
21.
Step 7 -
Results class HelloWorld { String name def greet() { quot;Hello $namequot; } } def helloWorld = new HelloWorld(name:quot;Groovyquot;) println helloWorld.greet() Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 21
22.
We came from
here… public class HelloWorld { String name; public void setName(String name) { this.name = name; } public String getName(){ return name; } public String greet() { return quot;Hello quot;+ name; } public static void main(String args[]){ HelloWorld helloWorld = new HelloWorld() helloWorld.setName(quot;Groovyquot;) System.err.println( helloWorld.greet() ) } } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 22
23.
… to here
class HelloWorld { String name def greet() { quot;Hello $namequot; } } def helloWorld = new HelloWorld(name:quot;Groovyquot;) println helloWorld.greet() Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 23
24.
Introduction to Groovy
| © 2009 by «Andres Almiray»; made available under the EPL v1.0 24
25.
Java-like Features
Close to home © 2009 by «Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
26.
Java -like features
• A Java class is a Groovy class, a Groovy class is a Java class • Full JDK5 support: annotations, generics, varargs, enums, enhanced for loop (this requires JRE5) • 98% of Java code is valid Groovy code Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 26
27.
Varargs in action
class Calculator { def addAllGroovy( Object[] args ){ int total = 0 for( i in args ) { total += i } total } def addAllJava( int... args ){ int total = 0 for( i in args ) { total += i } total } } Calculator c = new Calculator() assert c.addAllGroovy(1,2,3,4,5) == 15 assert c.addAllJava(1,2,3,4,5) == 15 Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 27
28.
Scott Davis' 1st
mantra: Java is Groovy, Groovy is Java Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 28
29.
Not-Java Features
Explore the Neighborhood © 2009 by «Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
30.
Assorted goodies
• Default parameter values as in PHP • Named parameters as in Ruby (reuse the Map trick of default POGO constructor) • Operator overloading, using a naming convention, for example + plus() [] getAt() / putAt() << leftShift() Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 30
31.
Closures
• Closures can be seen as reusable blocks of code, you may have seen them in JavaScript and Ruby among other languages. • Closures substitute inner classes in almost all use cases. • Groovy allows type coercion of a Closure into a one- method interface • A closure will have a default parameter named it if you do not define one. Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 31
32.
Examples of closures
def greet = { name -> println “Hello $name” } greet( “Groovy” ) // prints Hello Groovy def greet = { println “Hello $it” } greet( “Groovy” ) // prints Hello Groovy def iCanHaveTypedParametersToo = { int x, int y -> println “coordinates are ($x,$y)” } def myActionListener = { event -> // do something cool with event } as ActionListener Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 32
33.
With closures comes
currying • Currying is a programming technique that transforms a function into another while fixing one or more input values (think constants). Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 33
34.
Currying in action
// a closure with 3 parameters, the third one is optional // as it defines a default value def getSlope = { x, y, b = 0 -> println quot;x:${x} y:${y} b:${b}quot; (y - b) / x } assert 1 == getSlope( 2, 2 ) def getSlopeX = getSlope.curry(5) assert 1 == getSlopeX(5) assert 0 == getSlopeX(2.5,2.5) // prints // x:2 y:2 b:0 // x:5 y:5 b:0 // x:5 y:2.5 b:2.5 Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 34
35.
Iterators everywhere
• Like in Ruby you may use iterators in almost any context, Groovy will figure out what to do in each case • Iterators harness the power of closures, all iterators accept a closure as parameter. • Iterators relieve you of the burden of looping constructs Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 35
36.
Iterators in action
def printIt = { println it } // 3 ways to iterate from 1 to 5 [1,2,3,4,5].each printIt 1.upto 5, printIt (1..5).each printIt // compare to a regular loop for( i in [1,2,3,4,5] ) printIt(i) // same thing but use a Range for( i in (1..5) ) printIt(i) [1,2,3,4,5].eachWithIndex { v, i -> println quot;list[$i] => $vquot; } // list[0] => 1 // list[1] => 2 // list[2] => 3 // list[3] => 4 // list[4] => 5 Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 36
37.
Scott Davis' 2nd
mantra: Groovy is Java and Groovy is NOT Java Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 37
38.
Unique Features
Space out! © 2009 by «Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
39.
The as keyword
• Used for “Groovy casting”, convert a value of typeA into a value of typeB def intarray = [1,2,3] as int[ ] • Used to coerce a closure into an implementation of single method interface. • Used to coerce a Map into an implementation of an interface, abstract and/or concrete class. • Used to create aliases on imports Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 39
40.
Some examples of
as import javax.swing.table.DefaultTableCellRenderer as DTCR def myActionListener = { event -> // do something cool with event } as ActionListener def renderer = [ getTableCellRendererComponent: { t, v, s, f, r, c -> // cool renderer code goes here } ] as DTCR // note that this technique is like creating objects in // JavaScript with JSON format // it also circumvents the fact that Groovy can’t create // inner classes (yet) Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 40
41.
New operators
• ?: (elvis) - a refinement over the ternary operator • ?. Safe dereference – navigate an object graph without worrying on NPEs • <=> (spaceship) – compares two values • * (spread) – “explode” the contents of a list or array • *. (spread-dot) – apply a method call to every element of a list or array Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 41
42.
Traversing object graphs
• GPath is to objects what XPath is to XML. • *. and ?. come in handy in many situations • Because POGOs accept dot and bracket notation for property access its very easy to write GPath expressions. Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 42
43.
Sample GPath expressions
class Person { String name int id } def persons = [ new Person( name: 'Duke', id: 1 ), [name: 'Tux', id: 2] as Person ] assert [1,2] == persons.id assert ['Duke','Tux'] == persons*.getName() assert null == persons[2]?.name assert 'Duke' == persons[0].name ?: 'Groovy' assert 'Groovy' == persons[2]?.name ?: 'Groovy' Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 43
44.
MetaProgramming
• You can add methods and properties to any object at runtime. • You can intercept calls to method invocations and/or property access (similar to doing AOP but without the hassle). • This means Groovy offers a similar concept to Ruby’s open classes, Groovy even extends final classes as String and Integer with new methods (we call it GDK). Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 44
45.
A simple example
using categories class Pouncer { static pounce( Integer self ){ def s = “Boing!quot; 1.upto(self-1) { s += quot; boing!quot; } s + quot;!quot; } } use( Pouncer ){ assert 3.pounce() == “Boing! boing! boing!quot; } Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 45
46.
Same example using
MetaClasses Integer.metaClass.pounce << { -> def s = “Boing!quot; delegate.upto(delegate-1) { s += quot; boing!quot; } s + quot;!“ } assert 3.pounce() == “Boing! boing! boing!quot; Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 46
47.
More options in
Groovy 1.6! • Compile time metaprogramming via AST transformations • Runtime mixins Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 47
48.
Scott Davis says:
Groovy is what the Java language would look like had it been written in the 21st century Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 48
49.
Eclipse & Groovy ©
2009 by «Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
50.
Eclipse Plugin
• Allows you to edit, compile and run groovy scripts and classes. • Syntax coloring • Autocompletion • Groovy nature • Great support from Eclipse +3.2 series Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 50
51.
How to install
1. Go to Help -> Software Updates -> Find and Install 2. Configure a new update site http://dist.codehaus.org/groovy/distributions/update/ 3. Follow the wizard instructions 4. Restart Eclipse. You are now ready to start Groovying! Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 51
52.
Resources
• Groovy Language, guides, examples http://groovy.codehaus.org • Groovy Eclipse Plugin http://groovy.codehaus.org/Eclipse+Plugin • Groovy Related News http://aboutgroovy.com http://groovyblogs.org http://groovy.dzone.com • My Groovy/Java/Swing blog http://jroller.com/aalmiray http://twitter.com/aalmiray Introduction to Groovy | © 2009 by «Andres Almiray»; made available under the EPL v1.0 52
53.
Q&A © 2009 by
«Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
54.
Thank you! © 2009
by «Andres Almiray»; made available under the EPL v1.0 | 03/25/2009
Jetzt herunterladen