SlideShare a Scribd company logo
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

More Related Content

What's hot

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 developers
Puneet 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
 
Revealing ALLSTOCKER
Revealing ALLSTOCKERRevealing ALLSTOCKER
Revealing ALLSTOCKER
Masashi Umezawa
 
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
Dvir 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 - Week7
Devang Garach
 
Tangram
TangramTangram
Tangram
Yubei Li
 
PHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLiPHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLi
Marcos Marcolin
 
My talk on Piter Py 2016
My talk on Piter Py 2016My talk on Piter Py 2016
My talk on Piter Py 2016
Alex 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 Toolbox
WebCamp
 
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
Undo
 
Ruby on Docker
Ruby on DockerRuby on Docker
Ruby on Docker
jasnow
 
NodeJS
NodeJSNodeJS
NodeJS
Alok Guha
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
Arvind Devaraj
 
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 gdb
gregthelaw
 
Writing NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in HaskellWriting NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in Haskell
Kiwamu Okabe
 
A Look at Command Line Swift
A Look at Command Line SwiftA Look at Command Line Swift
A Look at Command Line Swift
JoshuaKaplan22
 
NodeJS
NodeJSNodeJS

What's hot (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
 

Viewers also liked

Literate Programming
Literate ProgrammingLiterate Programming
Literate Programming
Charles Anderson
 
December 2 General Meeting
December 2 General MeetingDecember 2 General Meeting
December 2 General Meeting
MSU PRSSA
 
一流企业员工应具备的心态
一流企业员工应具备的心态一流企业员工应具备的心态
一流企业员工应具备的心态20004
 
企业人力资源管理
企业人力资源管理企业人力资源管理
企业人力资源管理20004
 
职业经理人的心态与解压
职业经理人的心态与解压职业经理人的心态与解压
职业经理人的心态与解压20004
 
现代商务礼仪指引
现代商务礼仪指引现代商务礼仪指引
现代商务礼仪指引20004
 
It Service Green Tech V5webprint
It Service Green Tech V5webprintIt Service Green Tech V5webprint
It Service Green Tech V5webprint
manavsingh
 
聚成团队复制之人员招聘
聚成团队复制之人员招聘聚成团队复制之人员招聘
聚成团队复制之人员招聘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 Bath
JABVAB
 
职前培训安排(好)
职前培训安排(好)职前培训安排(好)
职前培训安排(好)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 2014
Charles Anderson
 

Viewers also liked (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
 

Similar to 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 Laforge
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
loffenauer
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
Eric 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 Lane
Andres Almiray
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres 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
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
Marc 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 Groovy
Andres 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 Laforge
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
Kostas Saidis
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
Guillaume 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 Applications
rohitnayak
 
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
Kostas Saidis
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
Tobias 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 Ruby
Anis 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 Developers
Kostas 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 Code
Paulo Traça
 

Similar to 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
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
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
 

More from Charles Anderson

Modern php
Modern phpModern php
Modern php
Charles Anderson
 
Inrastructure as Code
Inrastructure as CodeInrastructure as Code
Inrastructure as Code
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 Experience
Charles Anderson
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to Redis
Charles 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 JVM
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 Experience
Charles 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 Online
Charles Anderson
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and Java
Charles Anderson
 

More from 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
 

Recently uploaded

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

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