Enviar pesquisa
Carregar
Eclipsecon09 Introduction To Groovy
•
4 gostaram
•
3,967 visualizações
Andres Almiray
Seguir
Eclipsecon09 Introduction to Groovy
Leia menos
Leia mais
Tecnologia
Diversão e humor
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 54
Baixar agora
Baixar para ler offline
Recomendados
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
Recomendados
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
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres Almiray
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
James Williams
名古屋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
Mais conteúdo relacionado
Semelhante a 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
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres Almiray
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
James Williams
名古屋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
Semelhante a 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
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
名古屋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
Mais de 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
Mais de 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
Último
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
Florian Wilhelm
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
Curtis Poe
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Slibray Presentation
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Precisely
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
Lonnie McRorey
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
UiPathCommunity
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
Fwdays
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
Alan Dix
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Zilliz
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Mark Simos
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Fwdays
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
Dilum Bandara
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
Fwdays
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
Sri Ambati
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
Alfredo García Lavilla
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
Manik S Magar
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
Lars Bell
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
Commit University
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
Dubai Multi Commodity Centre
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
Stephanie Beckett
Último
(20)
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
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
Baixar agora