SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
Groovy: a Scripting
 Language for Java
        Charles Anderson
    Western Skies Consulting
  cander@westernskiesweb.com
Outline

• Introduction and Context
• Stupid Pet Tricks
• Using Groovy in a Java project
• Conclusion
• Grails?
Introduction
• There are now many dynamic and/or
  scripting languages that run on the Java
  Platform
• Groovy is a scripting language specifically for
  the Java Platform - feature-rich, Java-friendly
• Groovy compiles to Java classes & byte
  code - can use all of Java Platform
Introduction

• Scripting - don’t have to explicitly compile
• Typing - static or dynamic (optional/duck)
• Mature - version 1.5, 1.6 Beta 2
 • Books, websites, commercial backing, JSR
• IDE Support
Code Comparison


 Groovy     Groovy


Java          Java


 Syntax   Functionality
Java or Groovy?
class Book {
  private String title;
  Book (String theTitle) {
    title = theTitle;
  }
  String getTitle() {
    return title
  }
}
Stupid Pet Tricks
public class Main {
  public static void main(...)
    System.out.println(“Hello
    World”);
  }}

println ‘Hello World’
More Powerful Switch
switch   (x) {
  case   0:     // single int
  case   1..9: // range
  case   [11,13,17]: // list
  case   Float: // type check
  case   ‘cat’: // string
  case   ~/[A-Z][0-9]/: //regexp
}
Groovy Beans
public class MyBean implements
Serializable {
  private String myProp;
  public String getMyProp()...
  public void setMyProp(...)...
}
class MyBean implements Serializable {
  String myProp;
}
Terse NPE Safety

if (x!=null && x.y!=null) {
  z = x.y.z;
}

z = x?.y?.z
Bob the Builder
writer = new FileWriter(‘bob.html’)
def page = new MarkupBuilder(writer)
page.html{
  head { title ‘An HTML Page’ }
  body {
    h1 ‘The big heading’
    form (action:’submit’) {
      input(type:’checkbox’, id:’yes’)
      input(type:’checkbox’, id:’no’)
}}}
Closures
• A closure is a chunk of code that is a first-
  class entity/object in the language
  • From functional programming
• Can accept parameters and return a value
• Typical Java solution: inner classes, visitor
  pattern, template method pattern
Exorcising Inner
       Classes
t = new Thread(new Runable() {
  public void run() {
    // some code
  }});
t.start();

Thread.start { //some code }
Java Iteration
for (Iterator it=coll.iterator();
     it.hasNext(); ) {
  Item item=(Item)it.next();
  //some code
}

for (Item item : coll) {
  // some code
}
Groovy Iteration

coll.each(item-> // some code)

coll.findAll(it % 2 == 0).each(...)

new File(‘foo.txt’).eachLine {
                       println it }
Embrace and Extend
• Groovy “extends” Java classes - GDK
 • Object, GString, Collections, Files,
    Threads, Beans
• Groovy enhances existing Java tools
 • JUnit, Ant, Swing
• Reduce tedious boiler-plate - DRY
using Groovy

• Little development tasks - automation
 • Can script COM and Windows
• Experiments and spiking
• Testing - unit tests, data loading, scaffolding
Conclusion
• Groovy is a dynamic scripting language that
  is designed specifically for Java
• Lots of “tricks” to make life easier, but they
  can be introduced gradually
• Groovy is a playground for the future of
  Java - e.g., closures, properties
• Questions, job leads, Grails?
Grails: Groovy on Rails
• Accelerate and simplify web development
  on the Java Platform - but not Java Language
 • Deploys as a WAR file
• MVC structure
• Convention over configuration
• Uses Spring and Hibernate under covers
Grails Commands
Usage: grails command
  create-app
  run-app
  create-domain-class Entity
  generate-all Entity
  generate-webtest
  run-webtest
  war

Mais conteúdo relacionado

Mais procurados

Web technologies for desktop development
Web technologies for desktop developmentWeb technologies for desktop development
Web technologies for desktop developmentDarko Kukovec
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developersPuneet Behl
 
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...tdc-globalcode
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about goDvir Volk
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Devang Garach
 
PHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLiPHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLiMarcos Marcolin
 
My talk on Piter Py 2016
My talk on Piter Py 2016My talk on Piter Py 2016
My talk on Piter Py 2016Alex Chistyakov
 
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect ToolboxWebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect ToolboxWebCamp
 
GDB: A Lot More Than You Knew
GDB: A Lot More Than You KnewGDB: A Lot More Than You Knew
GDB: A Lot More Than You KnewUndo
 
Ruby on Docker
Ruby on DockerRuby on Docker
Ruby on Dockerjasnow
 
Why use JavaScript in Hardware? GoTo Conf - Berlin
Why use JavaScript in Hardware? GoTo Conf - Berlin Why use JavaScript in Hardware? GoTo Conf - Berlin
Why use JavaScript in Hardware? GoTo Conf - Berlin TechnicalMachine
 
Give me 15 minutes and i'll change your view of gdb
Give me 15 minutes and i'll change your view of gdbGive me 15 minutes and i'll change your view of gdb
Give me 15 minutes and i'll change your view of gdbgregthelaw
 
Writing NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in HaskellWriting NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in HaskellKiwamu Okabe
 
A Look at Command Line Swift
A Look at Command Line SwiftA Look at Command Line Swift
A Look at Command Line SwiftJoshuaKaplan22
 

Mais procurados (20)

Web technologies for desktop development
Web technologies for desktop developmentWeb technologies for desktop development
Web technologies for desktop development
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developers
 
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
 
Revealing ALLSTOCKER
Revealing ALLSTOCKERRevealing ALLSTOCKER
Revealing ALLSTOCKER
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
Tangram
TangramTangram
Tangram
 
PHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLiPHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLi
 
My talk on Piter Py 2016
My talk on Piter Py 2016My talk on Piter Py 2016
My talk on Piter Py 2016
 
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect ToolboxWebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
 
GDB: A Lot More Than You Knew
GDB: A Lot More Than You KnewGDB: A Lot More Than You Knew
GDB: A Lot More Than You Knew
 
Ruby on Docker
Ruby on DockerRuby on Docker
Ruby on Docker
 
NodeJS
NodeJSNodeJS
NodeJS
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Why use JavaScript in Hardware? GoTo Conf - Berlin
Why use JavaScript in Hardware? GoTo Conf - Berlin Why use JavaScript in Hardware? GoTo Conf - Berlin
Why use JavaScript in Hardware? GoTo Conf - Berlin
 
Give me 15 minutes and i'll change your view of gdb
Give me 15 minutes and i'll change your view of gdbGive me 15 minutes and i'll change your view of gdb
Give me 15 minutes and i'll change your view of gdb
 
Writing NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in HaskellWriting NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in Haskell
 
A Look at Command Line Swift
A Look at Command Line SwiftA Look at Command Line Swift
A Look at Command Line Swift
 
Node.js and Ruby
Node.js and RubyNode.js and Ruby
Node.js and Ruby
 
NodeJS
NodeJSNodeJS
NodeJS
 

Destaque

December 2 General Meeting
December 2 General MeetingDecember 2 General Meeting
December 2 General MeetingMSU PRSSA
 
一流企业员工应具备的心态
一流企业员工应具备的心态一流企业员工应具备的心态
一流企业员工应具备的心态20004
 
企业人力资源管理
企业人力资源管理企业人力资源管理
企业人力资源管理20004
 
职业经理人的心态与解压
职业经理人的心态与解压职业经理人的心态与解压
职业经理人的心态与解压20004
 
现代商务礼仪指引
现代商务礼仪指引现代商务礼仪指引
现代商务礼仪指引20004
 
It Service Green Tech V5webprint
It Service Green Tech V5webprintIt Service Green Tech V5webprint
It Service Green Tech V5webprintmanavsingh
 
聚成团队复制之人员招聘
聚成团队复制之人员招聘聚成团队复制之人员招聘
聚成团队复制之人员招聘20004
 
启迪培训公司
启迪培训公司启迪培训公司
启迪培训公司20004
 
Seven Habits
Seven HabitsSeven Habits
Seven Habits20004
 
择业心态
择业心态择业心态
择业心态20004
 
团队建设
团队建设团队建设
团队建设20004
 
Intro To Design Kitchen Bath
Intro To Design Kitchen BathIntro To Design Kitchen Bath
Intro To Design Kitchen BathJABVAB
 
职前培训安排(好)
职前培训安排(好)职前培训安排(好)
职前培训安排(好)20004
 
《跟你的产品谈恋爱》
《跟你的产品谈恋爱》《跟你的产品谈恋爱》
《跟你的产品谈恋爱》20004
 
研发中心08年度计划书打印版
研发中心08年度计划书打印版研发中心08年度计划书打印版
研发中心08年度计划书打印版20004
 
Docker - Hack Salem! - November 2014
Docker - Hack Salem! - November 2014Docker - Hack Salem! - November 2014
Docker - Hack Salem! - November 2014Charles Anderson
 

Destaque (20)

Literate Programming
Literate ProgrammingLiterate Programming
Literate Programming
 
December 2 General Meeting
December 2 General MeetingDecember 2 General Meeting
December 2 General Meeting
 
一流企业员工应具备的心态
一流企业员工应具备的心态一流企业员工应具备的心态
一流企业员工应具备的心态
 
企业人力资源管理
企业人力资源管理企业人力资源管理
企业人力资源管理
 
职业经理人的心态与解压
职业经理人的心态与解压职业经理人的心态与解压
职业经理人的心态与解压
 
现代商务礼仪指引
现代商务礼仪指引现代商务礼仪指引
现代商务礼仪指引
 
It Service Green Tech V5webprint
It Service Green Tech V5webprintIt Service Green Tech V5webprint
It Service Green Tech V5webprint
 
聚成团队复制之人员招聘
聚成团队复制之人员招聘聚成团队复制之人员招聘
聚成团队复制之人员招聘
 
启迪培训公司
启迪培训公司启迪培训公司
启迪培训公司
 
Seven Habits
Seven HabitsSeven Habits
Seven Habits
 
择业心态
择业心态择业心态
择业心态
 
团队建设
团队建设团队建设
团队建设
 
Intro To Design Kitchen Bath
Intro To Design Kitchen BathIntro To Design Kitchen Bath
Intro To Design Kitchen Bath
 
7
77
7
 
Clip
ClipClip
Clip
 
职前培训安排(好)
职前培训安排(好)职前培训安排(好)
职前培训安排(好)
 
《跟你的产品谈恋爱》
《跟你的产品谈恋爱》《跟你的产品谈恋爱》
《跟你的产品谈恋爱》
 
研发中心08年度计划书打印版
研发中心08年度计划书打印版研发中心08年度计划书打印版
研发中心08年度计划书打印版
 
1
11
1
 
Docker - Hack Salem! - November 2014
Docker - Hack Salem! - November 2014Docker - Hack Salem! - November 2014
Docker - Hack Salem! - November 2014
 

Semelhante a Groovy a Scripting Language for Java

Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGuillaume Laforge
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails IntroductionEric Weimer
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyJames Williams
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingAndres Almiray
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyAndres Almiray
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersKostas Saidis
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applicationsrohitnayak
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemKostas Saidis
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsTobias Oetiker
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with RubyAnis Ahmad
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersKostas Saidis
 
JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!Iván López Martín
 
Groovy Up Your Code
Groovy Up Your CodeGroovy Up Your Code
Groovy Up Your CodePaulo Traça
 

Semelhante a Groovy a Scripting Language for Java (20)

OpenLogic
OpenLogicOpenLogic
OpenLogic
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with Ruby
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
 
JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!
 
Groovy Up Your Code
Groovy Up Your CodeGroovy Up Your Code
Groovy Up Your Code
 

Mais de Charles Anderson

How to get a Software Job w/o Experience
How to get a Software Job w/o ExperienceHow to get a Software Job w/o Experience
How to get a Software Job w/o ExperienceCharles Anderson
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to RedisCharles Anderson
 
A Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMA Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMCharles Anderson
 
How to Get a Software Job w/o Experience
How to Get a Software Job w/o ExperienceHow to Get a Software Job w/o Experience
How to Get a Software Job w/o ExperienceCharles Anderson
 
How To Protect Yourself and Your Computer Online
How To Protect Yourself and Your Computer OnlineHow To Protect Yourself and Your Computer Online
How To Protect Yourself and Your Computer OnlineCharles Anderson
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and JavaCharles Anderson
 

Mais de Charles Anderson (8)

Modern php
Modern phpModern php
Modern php
 
Inrastructure as Code
Inrastructure as CodeInrastructure as Code
Inrastructure as Code
 
How to get a Software Job w/o Experience
How to get a Software Job w/o ExperienceHow to get a Software Job w/o Experience
How to get a Software Job w/o Experience
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to Redis
 
A Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMA Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVM
 
How to Get a Software Job w/o Experience
How to Get a Software Job w/o ExperienceHow to Get a Software Job w/o Experience
How to Get a Software Job w/o Experience
 
How To Protect Yourself and Your Computer Online
How To Protect Yourself and Your Computer OnlineHow To Protect Yourself and Your Computer Online
How To Protect Yourself and Your Computer Online
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and Java
 

Último

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Último (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Groovy a Scripting Language for Java

  • 1. Groovy: a Scripting Language for Java Charles Anderson Western Skies Consulting cander@westernskiesweb.com
  • 2. Outline • Introduction and Context • Stupid Pet Tricks • Using Groovy in a Java project • Conclusion • Grails?
  • 3. Introduction • There are now many dynamic and/or scripting languages that run on the Java Platform • Groovy is a scripting language specifically for the Java Platform - feature-rich, Java-friendly • Groovy compiles to Java classes & byte code - can use all of Java Platform
  • 4. Introduction • Scripting - don’t have to explicitly compile • Typing - static or dynamic (optional/duck) • Mature - version 1.5, 1.6 Beta 2 • Books, websites, commercial backing, JSR • IDE Support
  • 5. Code Comparison Groovy Groovy Java Java Syntax Functionality
  • 6. Java or Groovy? class Book { private String title; Book (String theTitle) { title = theTitle; } String getTitle() { return title } }
  • 7. Stupid Pet Tricks public class Main { public static void main(...) System.out.println(“Hello World”); }} println ‘Hello World’
  • 8. More Powerful Switch switch (x) { case 0: // single int case 1..9: // range case [11,13,17]: // list case Float: // type check case ‘cat’: // string case ~/[A-Z][0-9]/: //regexp }
  • 9. Groovy Beans public class MyBean implements Serializable { private String myProp; public String getMyProp()... public void setMyProp(...)... } class MyBean implements Serializable { String myProp; }
  • 10. Terse NPE Safety if (x!=null && x.y!=null) { z = x.y.z; } z = x?.y?.z
  • 11. Bob the Builder writer = new FileWriter(‘bob.html’) def page = new MarkupBuilder(writer) page.html{ head { title ‘An HTML Page’ } body { h1 ‘The big heading’ form (action:’submit’) { input(type:’checkbox’, id:’yes’) input(type:’checkbox’, id:’no’) }}}
  • 12. Closures • A closure is a chunk of code that is a first- class entity/object in the language • From functional programming • Can accept parameters and return a value • Typical Java solution: inner classes, visitor pattern, template method pattern
  • 13. Exorcising Inner Classes t = new Thread(new Runable() { public void run() { // some code }}); t.start(); Thread.start { //some code }
  • 14. Java Iteration for (Iterator it=coll.iterator(); it.hasNext(); ) { Item item=(Item)it.next(); //some code } for (Item item : coll) { // some code }
  • 15. Groovy Iteration coll.each(item-> // some code) coll.findAll(it % 2 == 0).each(...) new File(‘foo.txt’).eachLine { println it }
  • 16. Embrace and Extend • Groovy “extends” Java classes - GDK • Object, GString, Collections, Files, Threads, Beans • Groovy enhances existing Java tools • JUnit, Ant, Swing • Reduce tedious boiler-plate - DRY
  • 17. using Groovy • Little development tasks - automation • Can script COM and Windows • Experiments and spiking • Testing - unit tests, data loading, scaffolding
  • 18. Conclusion • Groovy is a dynamic scripting language that is designed specifically for Java • Lots of “tricks” to make life easier, but they can be introduced gradually • Groovy is a playground for the future of Java - e.g., closures, properties • Questions, job leads, Grails?
  • 19. Grails: Groovy on Rails • Accelerate and simplify web development on the Java Platform - but not Java Language • Deploys as a WAR file • MVC structure • Convention over configuration • Uses Spring and Hibernate under covers
  • 20. Grails Commands Usage: grails command create-app run-app create-domain-class Entity generate-all Entity generate-webtest run-webtest war