0
Getting Groovy<br />
JVM Languages<br />Java<br />JRuby<br />Jython<br />
JVM Languages<br />Java<br />JRuby<br />Jython<br />
JVM Languages<br />Java<br />JRuby<br />Jython<br />Groovy<br />
Two Worlds Collide<br />Java<br />Perl<br />
Two Worlds Collide<br />Java<br />Perl<br />
Two Worlds Collide<br />Java<br />Perl<br />
Two Worlds Collide<br />Java<br />Perl<br />
Slurping files in Perl<br />
Slurping files in Perl<br />my $fh = open '<', $filename;<br />local $/ = undef;<br />my $contents = <$fh>;<br />
Slurping files in Perl<br />my $fh = open '<', $filename;<br />local $/ = undef;<br />my $contents = <$fh>;<br />Slurping ...
Slurping files in Perl<br />my $fh = open '<', $filename;<br />local $/ = undef;<br />my $contents = <$fh>;<br />Slurping ...
Java?<br />
Java?<br />StringBuilder contents = new StringBuilder();<br />try {<br />  BufferedReader input = new BufferedReader(new F...
Java’s True Character<br />
Java’s True Character<br />
What would Groovy do?<br />
What would Groovy do?<br />def contents = new File(filename) …<br />
What would Groovy do?<br />def contents = new File(filename)<br />.text<br />
XML Parsing<br /><langs type="current"> 	<language>Perl</language> 	<language>Java</language> 	<language>Groovy</language>...
XML Parsing<br /><langs type="current"> 	<language>Perl</language> 	<language>Java</language> 	<language>Groovy</language>...
XML Parsing<br /><langs type="current"> 	<language>Perl</language> 	<language>Java</language> 	<language>Groovy</language>...
XML Parsing in Groovy<br /><langs type="current"> 	<language>Perl</language> 	<language>Java</language> 	<language>Groovy<...
XML Parsing in Groovy<br /><langs type="current"> 	<language>Perl</language> 	<language>Java</language> 	<language>Groovy<...
XML Parsing in Groovy<br /><langs type="current"> 	<language>Perl</language> 	<language>Java</language> 	<language>Groovy<...
Upcoming SlideShare
Loading in...5
×

Getting groovy

428

Published on

Why Groovy is a nicer and more productive language than Java.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
428
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Wait – that’s too verbose…
  • “it” is shorthand – a default parameter, like Perl’s $_
  • Transcript of "Getting groovy"

    1. 1. Getting Groovy<br />
    2. 2. JVM Languages<br />Java<br />JRuby<br />Jython<br />
    3. 3. JVM Languages<br />Java<br />JRuby<br />Jython<br />
    4. 4. JVM Languages<br />Java<br />JRuby<br />Jython<br />Groovy<br />
    5. 5. Two Worlds Collide<br />Java<br />Perl<br />
    6. 6. Two Worlds Collide<br />Java<br />Perl<br />
    7. 7. Two Worlds Collide<br />Java<br />Perl<br />
    8. 8. Two Worlds Collide<br />Java<br />Perl<br />
    9. 9. Slurping files in Perl<br />
    10. 10. Slurping files in Perl<br />my $fh = open '<', $filename;<br />local $/ = undef;<br />my $contents = <$fh>;<br />
    11. 11. Slurping files in Perl<br />my $fh = open '<', $filename;<br />local $/ = undef;<br />my $contents = <$fh>;<br />Slurping in Ruby<br />
    12. 12. Slurping files in Perl<br />my $fh = open '<', $filename;<br />local $/ = undef;<br />my $contents = <$fh>;<br />Slurping in Ruby<br />file = File.open(filename, "rb")<br />contents = file.read<br />
    13. 13. Java?<br />
    14. 14. Java?<br />StringBuilder contents = new StringBuilder();<br />try {<br /> BufferedReader input = new BufferedReader(new FileReader(aFile));<br /> try {<br /> String line = null;<br /> while ( (line = input.readLine()) != null) {<br /> contents.append(line);<br /> contents.append(lineSeparator);<br /> }<br /> } finally { input.close(); }<br />} catch (IOException ex) { ex.printStackTrace(); }<br />... = contents.toString();<br />
    15. 15. Java’s True Character<br />
    16. 16. Java’s True Character<br />
    17. 17. What would Groovy do?<br />
    18. 18. What would Groovy do?<br />def contents = new File(filename) …<br />
    19. 19. What would Groovy do?<br />def contents = new File(filename)<br />.text<br />
    20. 20. XML Parsing<br /><langs type="current"> <language>Perl</language> <language>Java</language> <language>Groovy</language></langs><br />
    21. 21. XML Parsing<br /><langs type="current"> <language>Perl</language> <language>Java</language> <language>Groovy</language></langs><br />import org.w3c.dom.*;<br />import org.xml.sax.SAXException;<br />import javax.xml.parsers.*;<br />import java.io.IOException;<br />
    22. 22. XML Parsing<br /><langs type="current"> <language>Perl</language> <language>Java</language> <language>Groovy</language></langs><br />public class ParseXml {<br /> public static void main(String[] args) {<br /> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();<br /> try {<br /> DocumentBuilder db = dbf.newDocumentBuilder();<br /> Document doc = db.parse(“langs.xml");<br /> Element langs = doc.getDocumentElement();<br /> System.out.println("type = " + langs.getAttribute("type"));<br /> NodeList list = langs.getElementsByTagName("language");<br /> for(int i=0; i < list.getLength(); i++) {<br /> Element language = (Element) list.item(i);<br /> System.out.println(language.getTextContent());<br /> }<br /> } catch(ParserConfigurationException pce) { pce.printStackTrace(); }<br /> catch(SAXException se) { se.printStackTrace(); }<br /> catch(IOException ioe) { ioe.printStackTrace(); }<br /> }<br /> }<br />}<br />
    23. 23. XML Parsing in Groovy<br /><langs type="current"> <language>Perl</language> <language>Java</language> <language>Groovy</language></langs><br />
    24. 24. XML Parsing in Groovy<br /><langs type="current"> <language>Perl</language> <language>Java</language> <language>Groovy</language></langs><br />def langs = new XmlSlurper().parse("langs.xml")<br />println langs.@type<br />langs.language.each { elem -><br /> println elem<br />}<br />
    25. 25. XML Parsing in Groovy<br /><langs type="current"> <language>Perl</language> <language>Java</language> <language>Groovy</language></langs><br />def langs = new XmlSlurper().parse("langs.xml")<br />println langs.@type<br />langs.language.each {<br /> println it<br />}<br />
    26. 26. Configuration<br />foo {<br /> port = 80<br /> bar {<br /> baz {<br /> some.thing = "burp"<br /> }<br /> }<br />}<br />def config = new ConfigSlurper().parse(...)<br />def config = new ConfigSlurper()<br /> .parse(new File("config.groovy").toURL())<br />assert config.foo.port == 80<br />assert config.foo.bar.baz.some.thing == "burp"<br />
    27. 27. Environment Configuration<br />foo.bar = "baz"<br />something.else = 99<br />environments {<br />development {<br /> port = 8181<br /> db = "devdb"<br /> }<br />test {<br /> port = 8080<br /> db = "testdb"<br /> }<br />production {<br /> port = 80<br /> db = "proddb"<br /> }<br />}<br />ConfigSlurper("production")<br />
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×