SlideShare a Scribd company logo
Getting Groovy
Two Worlds Collide Java Perl
Two Worlds Collide Java Perl
Two Worlds Collide Java Perl
Two Worlds Collide Java Perl
JVM Languages Java JRuby Jython
JVM Languages Java JRuby Jython
JVM Languages Java JRuby Jython Groovy
What ’ s wrong with Java anyway?
Slurping files in Perl
Slurping files in Perl my $fh = open '<', $filename; local $/ = undef; my $contents = <$fh>;
Slurping files in Perl my $fh = open '<', $filename; local $/ = undef; my $contents = <$fh>; Slurping in Ruby
Slurping files in Perl my $fh = open '<', $filename; local $/ = undef; my $contents = <$fh>; file = File.open(filename, &quot;rb&quot;) contents = file.read Slurping in Ruby
Java?
Java? StringBuilder contents = new StringBuilder(); try { BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; while ( (line = input.readLine()) != null) {   contents.append(line);   contents.append(lineSeparator); } } finally { input.close(); } } catch (IOException ex) { ex.printStackTrace(); } ... = contents.toString();
Java’s True Character
Java’s True Character
What would Groovy do?
What would Groovy do? def contents = new File(filename) …
What would Groovy do? def contents = new File(filename)  .text
XML Parsing <langs type=&quot;current&quot;>  <language>Perl</language>  <language>Java</language>  <language>Groovy</language> </langs>
XML Parsing <langs type=&quot;current&quot;>  <language>Perl</language>  <language>Java</language>  <language>Groovy</language> </langs> import org.w3c.dom.*; import org.xml.sax.SAXException; import javax.xml.parsers.*; import java.io.IOException;
XML Parsing <langs type=&quot;current&quot;>  <language>Perl</language>  <language>Java</language>  <language>Groovy</language> </langs> public class ParseXml { public static void main(String[] args) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(“langs.xml&quot;); Element langs = doc.getDocumentElement(); System.out.println(&quot;type = &quot; + langs.getAttribute(&quot;type&quot;)); NodeList list = langs.getElementsByTagName(&quot;language&quot;); for(int i=0; i < list.getLength(); i++) { Element language = (Element) list.item(i); System.out.println(language.getTextContent()); } } catch(ParserConfigurationException pce) { pce.printStackTrace(); } catch(SAXException se) { se.printStackTrace(); } catch(IOException ioe) { ioe.printStackTrace(); } } } }
XML Parsing in Groovy <langs type=&quot;current&quot;>  <language>Perl</language>  <language>Java</language>  <language>Groovy</language> </langs>
XML Parsing in Groovy <langs type=&quot;current&quot;>  <language>Perl</language>  <language>Java</language>  <language>Groovy</language> </langs> def langs = new XmlSlurper().parse(&quot;langs.xml&quot;) println langs.@type langs.language.each { elem -> println elem }
XML Parsing in Groovy <langs type=&quot;current&quot;>  <language>Perl</language>  <language>Java</language>  <language>Groovy</language> </langs> def langs = new XmlSlurper().parse(&quot;langs.xml&quot;) println langs.@type langs.language.each { println it }
Closures (1..10).each {|i| print i, &quot;\n&quot; } (1..10).each {i -> println i } Ruby Groovy
Configuration def config = new ConfigSlurper().parse(...) def config = new ConfigSlurper() .parse(new File(&quot;config.groovy&quot;).toURL()) assert config.foo.port == 80 assert config.foo.bar.baz.some.thing == &quot;burp&quot; foo { port = 80 bar { baz {   some.thing = &quot;burp&quot;   } } }
Runtime Environments foo.bar = &quot;baz&quot; something.else = 99 environments  {   development  {   port = 8181   db = &quot;devdb&quot; }   test  {   port = 8080   db = &quot;testdb&quot;   }   production  {   port = 80   db = &quot;proddb&quot; } } ConfigSlurper(&quot;production&quot;)
More short-hand def result = a ? a : b The Elvis operator def result = a ?: b
More short-hand new Date().format('yyyy-MM-dd') Date formatting
ExpandoMetaClass Number.metaClass.getProperty = { propertyName -> if (propertyName == 'percent') { delegate / 100 } else { delegate } } println 20.percent // 0.20 println 17.5.percent // 0.175

More Related Content

PPTX
Getting groovy
ODP
Perl Moderno
KEY
Yapcasia2011 - Hello Embed Perl
PDF
New Features in PHP 5.3
PPT
Talk Unix Shell Script 1
KEY
GettingStartedWithPHP
PPT
Airlover 20030324 1
PDF
Perl 5.10
Getting groovy
Perl Moderno
Yapcasia2011 - Hello Embed Perl
New Features in PHP 5.3
Talk Unix Shell Script 1
GettingStartedWithPHP
Airlover 20030324 1
Perl 5.10

What's hot (20)

KEY
Kansai.pm 10周年記念 Plack/PSGI 入門
PPT
Talk Unix Shell Script
PPT
Php Training
ODP
Os Welton
PDF
Learning go for perl programmers
PDF
East Bay Ruby Tropo presentation
ODP
Whatsnew in-perl
PPT
2007 09 10 Fzi Training Groovy Grails V Ws
PDF
Resource-Oriented Web Services
PPTX
Php extensions
PPT
typemap in Perl/XS
PPTX
Writing and using php streams and sockets
PPTX
Socket programming with php
PDF
What's new in PHP 5.5
PPTX
Php extensions
PPT
基于 Google protobuf 的 webgame 网络协议设计
PPTX
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
ODP
using python module: doctest
PDF
Key features PHP 5.3 - 5.6
PPT
On UnQLite
Kansai.pm 10周年記念 Plack/PSGI 入門
Talk Unix Shell Script
Php Training
Os Welton
Learning go for perl programmers
East Bay Ruby Tropo presentation
Whatsnew in-perl
2007 09 10 Fzi Training Groovy Grails V Ws
Resource-Oriented Web Services
Php extensions
typemap in Perl/XS
Writing and using php streams and sockets
Socket programming with php
What's new in PHP 5.5
Php extensions
基于 Google protobuf 的 webgame 网络协议设计
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
using python module: doctest
Key features PHP 5.3 - 5.6
On UnQLite
Ad

Viewers also liked (16)

DOC
PDF
Application software
PPT
Xavier thoma
PDF
ershov911
PPT
Xavier thoma
PPT
Xavier thoma
PDF
How to keep a conversation going
PPT
Xavier thoma
PDF
Programmatic Trading_Wipro PoV
PPTX
Comunicación humana por medio de herramientas
PPTX
Baking
PPTX
สถานีอนามัย
PPT
Actividad parque chicaque
PPT
Parque chicaque
PPTX
あいう
PDF
Frilansdagen wordpress-xverige(2)
Application software
Xavier thoma
ershov911
Xavier thoma
Xavier thoma
How to keep a conversation going
Xavier thoma
Programmatic Trading_Wipro PoV
Comunicación humana por medio de herramientas
Baking
สถานีอนามัย
Actividad parque chicaque
Parque chicaque
あいう
Frilansdagen wordpress-xverige(2)
Ad

Similar to Getting groovy (ODP) (20)

ODP
What's new in Perl 5.10?
PPT
Ruby For Java Programmers
PDF
Good Evils In Perl
PPTX
Perl basics for Pentesters
PPT
Perl Xpath Lightning Talk
PPT
Php Simple Xml
PDF
Impacta - Show Day de Rails
ODP
Modern Perl
PPT
The JSON Saga
PPT
Jsonsaga
PPT
PHP 5 Sucks. PHP 5 Rocks.
PPT
Dealing with Legacy Perl Code - Peter Scott
PPT
Douglas Crockford Presentation Jsonsaga
PPT
Perl Presentation
PPT
Python - Getting to the Essence - Points.com - Dave Park
PPT
Ods Markup And Tagsets: A Tutorial
ODP
Advanced Perl Techniques
PPT
Writing Friendly libraries for CodeIgniter
PPT
spug_2008-08
PDF
Groovy on the Shell
What's new in Perl 5.10?
Ruby For Java Programmers
Good Evils In Perl
Perl basics for Pentesters
Perl Xpath Lightning Talk
Php Simple Xml
Impacta - Show Day de Rails
Modern Perl
The JSON Saga
Jsonsaga
PHP 5 Sucks. PHP 5 Rocks.
Dealing with Legacy Perl Code - Peter Scott
Douglas Crockford Presentation Jsonsaga
Perl Presentation
Python - Getting to the Essence - Points.com - Dave Park
Ods Markup And Tagsets: A Tutorial
Advanced Perl Techniques
Writing Friendly libraries for CodeIgniter
spug_2008-08
Groovy on the Shell

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Encapsulation theory and applications.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
Programs and apps: productivity, graphics, security and other tools
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation theory and applications.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Getting groovy (ODP)

  • 2. Two Worlds Collide Java Perl
  • 3. Two Worlds Collide Java Perl
  • 4. Two Worlds Collide Java Perl
  • 5. Two Worlds Collide Java Perl
  • 6. JVM Languages Java JRuby Jython
  • 7. JVM Languages Java JRuby Jython
  • 8. JVM Languages Java JRuby Jython Groovy
  • 9. What ’ s wrong with Java anyway?
  • 11. Slurping files in Perl my $fh = open '<', $filename; local $/ = undef; my $contents = <$fh>;
  • 12. Slurping files in Perl my $fh = open '<', $filename; local $/ = undef; my $contents = <$fh>; Slurping in Ruby
  • 13. Slurping files in Perl my $fh = open '<', $filename; local $/ = undef; my $contents = <$fh>; file = File.open(filename, &quot;rb&quot;) contents = file.read Slurping in Ruby
  • 14. Java?
  • 15. Java? StringBuilder contents = new StringBuilder(); try { BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; while ( (line = input.readLine()) != null) { contents.append(line); contents.append(lineSeparator); } } finally { input.close(); } } catch (IOException ex) { ex.printStackTrace(); } ... = contents.toString();
  • 19. What would Groovy do? def contents = new File(filename) …
  • 20. What would Groovy do? def contents = new File(filename) .text
  • 21. XML Parsing <langs type=&quot;current&quot;> <language>Perl</language> <language>Java</language> <language>Groovy</language> </langs>
  • 22. XML Parsing <langs type=&quot;current&quot;> <language>Perl</language> <language>Java</language> <language>Groovy</language> </langs> import org.w3c.dom.*; import org.xml.sax.SAXException; import javax.xml.parsers.*; import java.io.IOException;
  • 23. XML Parsing <langs type=&quot;current&quot;> <language>Perl</language> <language>Java</language> <language>Groovy</language> </langs> public class ParseXml { public static void main(String[] args) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(“langs.xml&quot;); Element langs = doc.getDocumentElement(); System.out.println(&quot;type = &quot; + langs.getAttribute(&quot;type&quot;)); NodeList list = langs.getElementsByTagName(&quot;language&quot;); for(int i=0; i < list.getLength(); i++) { Element language = (Element) list.item(i); System.out.println(language.getTextContent()); } } catch(ParserConfigurationException pce) { pce.printStackTrace(); } catch(SAXException se) { se.printStackTrace(); } catch(IOException ioe) { ioe.printStackTrace(); } } } }
  • 24. XML Parsing in Groovy <langs type=&quot;current&quot;> <language>Perl</language> <language>Java</language> <language>Groovy</language> </langs>
  • 25. XML Parsing in Groovy <langs type=&quot;current&quot;> <language>Perl</language> <language>Java</language> <language>Groovy</language> </langs> def langs = new XmlSlurper().parse(&quot;langs.xml&quot;) println langs.@type langs.language.each { elem -> println elem }
  • 26. XML Parsing in Groovy <langs type=&quot;current&quot;> <language>Perl</language> <language>Java</language> <language>Groovy</language> </langs> def langs = new XmlSlurper().parse(&quot;langs.xml&quot;) println langs.@type langs.language.each { println it }
  • 27. Closures (1..10).each {|i| print i, &quot;\n&quot; } (1..10).each {i -> println i } Ruby Groovy
  • 28. Configuration def config = new ConfigSlurper().parse(...) def config = new ConfigSlurper() .parse(new File(&quot;config.groovy&quot;).toURL()) assert config.foo.port == 80 assert config.foo.bar.baz.some.thing == &quot;burp&quot; foo { port = 80 bar { baz { some.thing = &quot;burp&quot; } } }
  • 29. Runtime Environments foo.bar = &quot;baz&quot; something.else = 99 environments { development { port = 8181 db = &quot;devdb&quot; } test { port = 8080 db = &quot;testdb&quot; } production { port = 80 db = &quot;proddb&quot; } } ConfigSlurper(&quot;production&quot;)
  • 30. More short-hand def result = a ? a : b The Elvis operator def result = a ?: b
  • 31. More short-hand new Date().format('yyyy-MM-dd') Date formatting
  • 32. ExpandoMetaClass Number.metaClass.getProperty = { propertyName -> if (propertyName == 'percent') { delegate / 100 } else { delegate } } println 20.percent // 0.20 println 17.5.percent // 0.175

Editor's Notes

  • #3: Perl and Java really don&apos;t get on
  • #6: Like Leeds United, Perl used to be incredibly popular, faded a bit, suddenly looked promising about a decade ago, and fans have been waiting ever since then for a big comeback. In the meantime, some of the star players have moved on to better things.
  • #7: So no JVM Perl yet.
  • #8: Integration between Java and most other JVM languages is usually in only one direction. It&apos;s easy to use Java libraries in jython/jruby, but harder to use java/jython code elsewhere in Java.
  • #9: Groovy generates Java classes, which can be packaged and used in Java alongside other jars.
  • #26: Wait – that’s too verbose…
  • #27: “ it ” is shorthand – a default parameter, like Perl’s $ _
  • #28: “ it ” is shorthand – a default parameter, like Perl’s $ _