SlideShare a Scribd company logo
Given Groovy Who Needs Java?

                                 Prof Russel Winder
                                  http://www.russel.org.uk

                                  email: russel@winder.org.uk
                                 xmpp: russel@winder.org.uk
                                    twitter: @russel_winder




Copyright © 2012 Russel Winder                                  1
Interstitial Advertisement




Copyright © 2012 Russel Winder                        2
Introduction




Copyright © 2012 Russel Winder                  3
Groovy was…
     ●   …designed to be a dynamic symbiote to Java.

     ●   Java is statically typed.
     ●   Groovy is optionally typed.




Copyright © 2012 Russel Winder                         4
Groovy was…
     ●   …designed to have a very lightweight syntax.

     ●   Literal syntax for lists and maps.
     ●   As little punctuation as possible.




Copyright © 2012 Russel Winder                          5
Groovy was…
     ●   …designed to work with code as first class entity.

     ●   Closures and functional approach from the outset.
     ●   No waiting for Java 8.




Copyright © 2012 Russel Winder                                6
Code




Copyright © 2012 Russel Winder          7
println 'Hello World.'




Copyright © 2012 Russel Winder                            8
public class testAll_GroovyTestCase extends GroovyTestCase {
  void test_helloWorld_trivial() {
     assert 'helloWorld_trivial.groovy'.execute().text == 'Hello World.n'
  }
}




                                 Power asserts


                                                 JUnit3 behind the scenes

Copyright © 2012 Russel Winder                                              9
@Grab('org.spockframework:spock:0.7-groovy2.0')
   import spock.lang.Specification

   class TestAll_Spock extends Specification {
      def "ensure the hello world program prints hello world"() {
        expect:
           'helloWorld_trivial.groovy'.execute().text == 'Hello World.n'
      }
   }




Copyright © 2012 Russel Winder                                              10
def datum = ['Hello', ' ', 'World', '.'].join('')

                   println datum




Copyright © 2012 Russel Winder                                         11
String datum = ['Hello', ' ', 'World', '.'].join('')

                   println datum




Copyright © 2012 Russel Winder                                            12
datum = ['Hello', ' ', 'World', '.'].join('')

                   println datum




Copyright © 2012 Russel Winder                                     13
words = [:]

                             words.third = 'World'
                             words << [first: 'Hello', fourth: '.']
                             words['second'] = ' '

                             sequence = ['first', 'second', 'third', 'fourth']

                             println(sequence.collect{words[it]}.join(''))




Copyright © 2012 Russel Winder                                                   14
@GrabResolver(name='atlassian',
    root='https://maven.atlassian.com/content/groups/public/')
  @Grab('org.swift.tools:gint:1.5.0')
  import org.swift.tools.Gint

  includeTool << Gint

  gint.initialize(this)

  new File('.').eachFileMatch(~/helloWorld_.*.groovy/) {
    gint.add(name: it.name, inline: { it.name.execute().text == 'Hello World.n' })
  }

  gint.finalizeTest()




Copyright © 2012 Russel Winder                                                        15
import groovy.xml.MarkupBuilder

                                 new MarkupBuilder().html{
                                   head{
                                     title 'Hello World.'
                                   }
                                   body{
                                     (0 ..< 3).each {
                                        em('Hello')
                                     }
                                   }
                                 }




Copyright © 2012 Russel Winder                                     16
<html>
                                   <head>
                                     <title>Hello World.</title>
                                   </head>
                                   <body>
                                     <em>Hello</em>
                                     <em>Hello</em>
                                     <em>Hello</em>
                                   </body>
                                 </html>




Copyright © 2012 Russel Winder                                     17
html = new XmlParser().parse(System.in)
                       assert html.head.title.text() == 'Hello World.'
                       assert html.body.em.text() == 'HelloHelloHello'




Copyright © 2012 Russel Winder                                           18
import javax.swing.WindowConstants

         import groovy.swing.SwingBuilder

         def widget = new SwingBuilder().frame(
            title: 'Hello World Window',
            size: [200, 100],
            defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE
         ){
            panel {
              button(text:'Say Hello', actionPerformed: { println 'Hello.' })
            }
         }
         widget.show()




Copyright © 2012 Russel Winder                                                  19
Copyright © 2012 Russel Winder   20
final n = 100000
                 final delta = 1.0 / n
                 final startTime = System.nanoTime()
                 def sum = 0.0
                 for (i in 1 .. n) { sum += 1 / (1 + ((i - 0.5) * delta) ** 2) }
                 final pi = 4 * delta * sum
                 final elapseTime = (System.nanoTime() - startTime) / 1e9
                 Output.out(getClass().name, pi, n, elapseTime)




Copyright © 2012 Russel Winder                                                     21
final int n = 1000000000
              final double delta = 1.0 / n
              final startTimeNanos = System.nanoTime()
              double sum = 0.0
              for (int i = 1; i <= n; ++i) {
                 final double x = (i - 0.5d) * delta
                 sum += 1.0d / (1.0d + x * x)
              }
              final double pi = 4.0 * delta * sum
              final elapseTime = (System.nanoTime() - startTimeNanos) / 1e9
              Output.out(getClass().name, pi, n, elapseTime)




Copyright © 2012 Russel Winder                                                22
import groovy.transform.CompileStatic

           @CompileStatic execute() {
             final int n = 1000000000
             final double delta = 1.0 / n
             final startTimeNanos = System.nanoTime ()
             double sum = 0.0
             for (int i = 1; i <= n; ++i) {
                final double x = (i - 0.5d) * delta
                sum += 1.0d / (1.0d + x * x)
             }
             final double pi = 4.0 * delta * sum
             final elapseTime = (System.nanoTime() - startTimeNanos) / 1e9
             Output.out(getClass().name, pi, n, elapseTime)
           }

           execute()
Copyright © 2012 Russel Winder                                               23
final int n = 10000000
                   final double delta = 1.0 / n
                   final startTime = System.nanoTime()
                   final double pi = 4.0 * delta * (1i .. n).sum {int i ->
                     final double x = (i - 0.5d) * delta
                     1.0d / (1.0d + x * x)
                   }
                   final elapseTime = (System.nanoTime() - startTime) / 1e9
                   Output.out(getClass().name, pi, n, elapseTime)




Copyright © 2012 Russel Winder                                                24
import groovy.transform.CompileStatic

                   @CompileStatic execute() {
                     final int n = 10000000
                     final double delta = 1.0 / n
                     final startTime = System.nanoTime()
                     final double pi = 4.0 * delta * (double)((1i .. n).sum {int i ->
                        final double x = (i - 0.5d) * delta
                        1.0d / (1.0d + x * x)
                     })
                     final elapseTime = (System.nanoTime() - startTime) / 1e9
                     Output.out(getClass().name, pi, n, elapseTime)
                   }

                   execute()



Copyright © 2012 Russel Winder                                                          25
import groovyx.gpars.ParallelEnhancer

                  void execute(final numberOfTasks) {
                    final n = 1000000000
                    final delta = 1.0 / n
                    final startTimeNanos = System.nanoTime ()
                    final sliceSize = (int)(n / numberOfTasks)
                    final items = 0 ..< numberOfTasks
                    ParallelEnhancer.enhanceInstance(items)
                    final pi = 4.0 * delta * items.collectParallel {taskId ->
                      PartialSum.dynamicCompile(taskId, sliceSize, delta)
                    }.sumParallel()
                    final elapseTime = (System.nanoTime() - startTimeNanos) / 1e9
                    Output.out(getClass().name, pi, n, elapseTime, numberOfTasks)
                  }

                  execute 1
                  execute 2
                  execute 8
                  execute 32


Copyright © 2012 Russel Winder                                                      26
static double dynamicCompile(final int taskId, final int sliceSize, final double delta) {
        final int start = 1i + taskId * sliceSize
        final int end = (taskId + 1i) * sliceSize
        double sum = 0.0d
        for (int i = start; i <= end; ++i) {
          final double x = (i - 0.5d) * delta
          sum += 1.0d / (1.0d + x * x)
        }
        sum
      }




Copyright © 2012 Russel Winder                                                                27
Conclusion




Copyright © 2012 Russel Winder                28
There is nothing that Java can do

                        that Groovy cannot do better.




Copyright © 2012 Russel Winder                          29
Interstitial Advertisement




Copyright © 2012 Russel Winder                        30
Given Groovy Who Needs Java?

                                 Prof Russel Winder
                                  http://www.russel.org.uk

                                  email: russel@winder.org.uk
                                 xmpp: russel@winder.org.uk
                                    twitter: @russel_winder




Copyright © 2012 Russel Winder                                  31
Challenge




Copyright © 2012 Russel Winder               32
Problem


                                                        Groovy
                 Java



                                   Develop faster
                                   Execute faster
                                   Can be done at all



Copyright © 2012 Russel Winder                                   33
Given Groovy Who Needs Java?

                                 Prof Russel Winder
                                  http://www.russel.org.uk

                                  email: russel@winder.org.uk
                                 xmpp: russel@winder.org.uk
                                    twitter: @russel_winder




Copyright © 2012 Russel Winder                                  34

More Related Content

PDF
Spock and Geb in Action
PDF
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
PDF
groovy databases
PDF
concurrency with GPars
PDF
Replication MongoDB Days 2013
PDF
JJUG CCC 2011 Spring
ODP
GPars (Groovy Parallel Systems)
PPTX
Replication and Replica Sets
Spock and Geb in Action
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
groovy databases
concurrency with GPars
Replication MongoDB Days 2013
JJUG CCC 2011 Spring
GPars (Groovy Parallel Systems)
Replication and Replica Sets

What's hot (20)

PDF
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
PDF
Di and Dagger
PDF
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
PDF
MySQL flexible schema and JSON for Internet of Things
PDF
The Ring programming language version 1.5.3 book - Part 78 of 184
PDF
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
PDF
Php user groupmemcached
PDF
The Ring programming language version 1.3 book - Part 51 of 88
PDF
The Ring programming language version 1.4.1 book - Part 16 of 31
PDF
The Ring programming language version 1.7 book - Part 51 of 196
PDF
Understanding Source Code Differences by Separating Refactoring Effects
PDF
Architecture Components In Real Life Season 2
PDF
MongoDB: Optimising for Performance, Scale & Analytics
PPTX
IPC: AIDL is sexy, not a curse
PPTX
Ipc: aidl sexy, not a curse
PPTX
concurrency gpars
PDF
Di web tech mail (no subject)
PDF
Android Architecture Component in Real Life
PDF
Python memory management_v2
PDF
Optimizing Slow Queries with Indexes and Creativity
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
Di and Dagger
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
MySQL flexible schema and JSON for Internet of Things
The Ring programming language version 1.5.3 book - Part 78 of 184
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
Php user groupmemcached
The Ring programming language version 1.3 book - Part 51 of 88
The Ring programming language version 1.4.1 book - Part 16 of 31
The Ring programming language version 1.7 book - Part 51 of 196
Understanding Source Code Differences by Separating Refactoring Effects
Architecture Components In Real Life Season 2
MongoDB: Optimising for Performance, Scale & Analytics
IPC: AIDL is sexy, not a curse
Ipc: aidl sexy, not a curse
concurrency gpars
Di web tech mail (no subject)
Android Architecture Component in Real Life
Python memory management_v2
Optimizing Slow Queries with Indexes and Creativity
Ad

Similar to Given Groovy Who Needs Java (20)

PDF
Closures: The Next "Big Thing" In Java
PDF
Closures, the next "Big Thing" in Java: Russel Winder
PDF
Spocktacular Testing
PDF
Spocktacular Testing - Russel Winder
PDF
Spocktacular testing
PDF
Android and the Seven Dwarfs from Devox'15
PDF
GPars: Parallelism the Right Way
PDF
ChtiJUG - Cassandra 2.0
PDF
Realm Java 2.2.0: Build better apps, faster apps
PDF
Realm Java 2.2.0: Build better apps, faster apps
KEY
Introduction to Groovy
PDF
Terrific Frontends
KEY
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
PDF
Gradleintroduction 111010130329-phpapp01
PDF
Gradle Introduction
PDF
From render() to DOM
PDF
Java9 Beyond Modularity - Java 9 más allá de la modularidad
PDF
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
PDF
.NET Coding Standards For The Real World (2012)
PDF
Node.js in action
Closures: The Next "Big Thing" In Java
Closures, the next "Big Thing" in Java: Russel Winder
Spocktacular Testing
Spocktacular Testing - Russel Winder
Spocktacular testing
Android and the Seven Dwarfs from Devox'15
GPars: Parallelism the Right Way
ChtiJUG - Cassandra 2.0
Realm Java 2.2.0: Build better apps, faster apps
Realm Java 2.2.0: Build better apps, faster apps
Introduction to Groovy
Terrific Frontends
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Gradleintroduction 111010130329-phpapp01
Gradle Introduction
From render() to DOM
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
.NET Coding Standards For The Real World (2012)
Node.js in action
Ad

More from Russel Winder (20)

PDF
On Concurrency and Parallelism in the JVMverse
PDF
The Case for Kotlin and Ceylon
PDF
On the Architectures of Microservices: the next layer
PDF
Fast Python? Don't Bother
PDF
Making Python computations fast
PDF
Tales from the Workshops
PDF
Making Computations Execute Very Quickly
PDF
Java is Dead, Long Live Ceylon, Kotlin, etc
PDF
GPars Remoting
PDF
Java is dead, long live Scala, Kotlin, Ceylon, etc.
PDF
GPars 2014
PDF
Is Groovy static or dynamic
PDF
Java is dead, long live Scala Kotlin Ceylon etc.
PDF
Dataflow: the concurrency/parallelism architecture you need
PDF
Are Go and D threats to Python
PDF
Is Groovy as fast as Java
PDF
Who needs C++ when you have D and Go
PDF
Java 8: a New Beginning
PDF
Why Go is an important programming language
ODP
GPars: Groovy Parallelism for Java
On Concurrency and Parallelism in the JVMverse
The Case for Kotlin and Ceylon
On the Architectures of Microservices: the next layer
Fast Python? Don't Bother
Making Python computations fast
Tales from the Workshops
Making Computations Execute Very Quickly
Java is Dead, Long Live Ceylon, Kotlin, etc
GPars Remoting
Java is dead, long live Scala, Kotlin, Ceylon, etc.
GPars 2014
Is Groovy static or dynamic
Java is dead, long live Scala Kotlin Ceylon etc.
Dataflow: the concurrency/parallelism architecture you need
Are Go and D threats to Python
Is Groovy as fast as Java
Who needs C++ when you have D and Go
Java 8: a New Beginning
Why Go is an important programming language
GPars: Groovy Parallelism for Java

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Approach and Philosophy of On baking technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
Approach and Philosophy of On baking technology

Given Groovy Who Needs Java

  • 1. Given Groovy Who Needs Java? Prof Russel Winder http://www.russel.org.uk email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder Copyright © 2012 Russel Winder 1
  • 4. Groovy was… ● …designed to be a dynamic symbiote to Java. ● Java is statically typed. ● Groovy is optionally typed. Copyright © 2012 Russel Winder 4
  • 5. Groovy was… ● …designed to have a very lightweight syntax. ● Literal syntax for lists and maps. ● As little punctuation as possible. Copyright © 2012 Russel Winder 5
  • 6. Groovy was… ● …designed to work with code as first class entity. ● Closures and functional approach from the outset. ● No waiting for Java 8. Copyright © 2012 Russel Winder 6
  • 7. Code Copyright © 2012 Russel Winder 7
  • 8. println 'Hello World.' Copyright © 2012 Russel Winder 8
  • 9. public class testAll_GroovyTestCase extends GroovyTestCase { void test_helloWorld_trivial() { assert 'helloWorld_trivial.groovy'.execute().text == 'Hello World.n' } } Power asserts JUnit3 behind the scenes Copyright © 2012 Russel Winder 9
  • 10. @Grab('org.spockframework:spock:0.7-groovy2.0') import spock.lang.Specification class TestAll_Spock extends Specification { def "ensure the hello world program prints hello world"() { expect: 'helloWorld_trivial.groovy'.execute().text == 'Hello World.n' } } Copyright © 2012 Russel Winder 10
  • 11. def datum = ['Hello', ' ', 'World', '.'].join('') println datum Copyright © 2012 Russel Winder 11
  • 12. String datum = ['Hello', ' ', 'World', '.'].join('') println datum Copyright © 2012 Russel Winder 12
  • 13. datum = ['Hello', ' ', 'World', '.'].join('') println datum Copyright © 2012 Russel Winder 13
  • 14. words = [:] words.third = 'World' words << [first: 'Hello', fourth: '.'] words['second'] = ' ' sequence = ['first', 'second', 'third', 'fourth'] println(sequence.collect{words[it]}.join('')) Copyright © 2012 Russel Winder 14
  • 15. @GrabResolver(name='atlassian', root='https://maven.atlassian.com/content/groups/public/') @Grab('org.swift.tools:gint:1.5.0') import org.swift.tools.Gint includeTool << Gint gint.initialize(this) new File('.').eachFileMatch(~/helloWorld_.*.groovy/) { gint.add(name: it.name, inline: { it.name.execute().text == 'Hello World.n' }) } gint.finalizeTest() Copyright © 2012 Russel Winder 15
  • 16. import groovy.xml.MarkupBuilder new MarkupBuilder().html{ head{ title 'Hello World.' } body{ (0 ..< 3).each { em('Hello') } } } Copyright © 2012 Russel Winder 16
  • 17. <html>   <head>     <title>Hello World.</title>   </head>   <body>     <em>Hello</em>     <em>Hello</em>     <em>Hello</em>   </body> </html> Copyright © 2012 Russel Winder 17
  • 18. html = new XmlParser().parse(System.in) assert html.head.title.text() == 'Hello World.' assert html.body.em.text() == 'HelloHelloHello' Copyright © 2012 Russel Winder 18
  • 19. import javax.swing.WindowConstants import groovy.swing.SwingBuilder def widget = new SwingBuilder().frame( title: 'Hello World Window', size: [200, 100], defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE ){ panel { button(text:'Say Hello', actionPerformed: { println 'Hello.' }) } } widget.show() Copyright © 2012 Russel Winder 19
  • 20. Copyright © 2012 Russel Winder 20
  • 21. final n = 100000 final delta = 1.0 / n final startTime = System.nanoTime() def sum = 0.0 for (i in 1 .. n) { sum += 1 / (1 + ((i - 0.5) * delta) ** 2) } final pi = 4 * delta * sum final elapseTime = (System.nanoTime() - startTime) / 1e9 Output.out(getClass().name, pi, n, elapseTime) Copyright © 2012 Russel Winder 21
  • 22. final int n = 1000000000 final double delta = 1.0 / n final startTimeNanos = System.nanoTime() double sum = 0.0 for (int i = 1; i <= n; ++i) { final double x = (i - 0.5d) * delta sum += 1.0d / (1.0d + x * x) } final double pi = 4.0 * delta * sum final elapseTime = (System.nanoTime() - startTimeNanos) / 1e9 Output.out(getClass().name, pi, n, elapseTime) Copyright © 2012 Russel Winder 22
  • 23. import groovy.transform.CompileStatic @CompileStatic execute() { final int n = 1000000000 final double delta = 1.0 / n final startTimeNanos = System.nanoTime () double sum = 0.0 for (int i = 1; i <= n; ++i) { final double x = (i - 0.5d) * delta sum += 1.0d / (1.0d + x * x) } final double pi = 4.0 * delta * sum final elapseTime = (System.nanoTime() - startTimeNanos) / 1e9 Output.out(getClass().name, pi, n, elapseTime) } execute() Copyright © 2012 Russel Winder 23
  • 24. final int n = 10000000 final double delta = 1.0 / n final startTime = System.nanoTime() final double pi = 4.0 * delta * (1i .. n).sum {int i -> final double x = (i - 0.5d) * delta 1.0d / (1.0d + x * x) } final elapseTime = (System.nanoTime() - startTime) / 1e9 Output.out(getClass().name, pi, n, elapseTime) Copyright © 2012 Russel Winder 24
  • 25. import groovy.transform.CompileStatic @CompileStatic execute() { final int n = 10000000 final double delta = 1.0 / n final startTime = System.nanoTime() final double pi = 4.0 * delta * (double)((1i .. n).sum {int i -> final double x = (i - 0.5d) * delta 1.0d / (1.0d + x * x) }) final elapseTime = (System.nanoTime() - startTime) / 1e9 Output.out(getClass().name, pi, n, elapseTime) } execute() Copyright © 2012 Russel Winder 25
  • 26. import groovyx.gpars.ParallelEnhancer void execute(final numberOfTasks) { final n = 1000000000 final delta = 1.0 / n final startTimeNanos = System.nanoTime () final sliceSize = (int)(n / numberOfTasks) final items = 0 ..< numberOfTasks ParallelEnhancer.enhanceInstance(items) final pi = 4.0 * delta * items.collectParallel {taskId -> PartialSum.dynamicCompile(taskId, sliceSize, delta) }.sumParallel() final elapseTime = (System.nanoTime() - startTimeNanos) / 1e9 Output.out(getClass().name, pi, n, elapseTime, numberOfTasks) } execute 1 execute 2 execute 8 execute 32 Copyright © 2012 Russel Winder 26
  • 27. static double dynamicCompile(final int taskId, final int sliceSize, final double delta) { final int start = 1i + taskId * sliceSize final int end = (taskId + 1i) * sliceSize double sum = 0.0d for (int i = start; i <= end; ++i) { final double x = (i - 0.5d) * delta sum += 1.0d / (1.0d + x * x) } sum } Copyright © 2012 Russel Winder 27
  • 28. Conclusion Copyright © 2012 Russel Winder 28
  • 29. There is nothing that Java can do that Groovy cannot do better. Copyright © 2012 Russel Winder 29
  • 31. Given Groovy Who Needs Java? Prof Russel Winder http://www.russel.org.uk email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder Copyright © 2012 Russel Winder 31
  • 32. Challenge Copyright © 2012 Russel Winder 32
  • 33. Problem Groovy Java Develop faster Execute faster Can be done at all Copyright © 2012 Russel Winder 33
  • 34. Given Groovy Who Needs Java? Prof Russel Winder http://www.russel.org.uk email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder Copyright © 2012 Russel Winder 34