SlideShare una empresa de Scribd logo
1 de 20
Tom Corcoran – OSS Software - May 2009 1 Get excited by coding again! Java History & the JVM Groovy genesis & it’s relation to Java Installing Groovy Live demo to compare and contrast Groovy with Java code Groovy 	Typing 	Object & Looping 	Regular Expressions 	Groovy Math 	Goodies+++ 	Closures 	MOP 	MLVM Grails & GAE
Tom Corcoran – OSS Software - May 2009 2 Java Javadeveloped by James Gosling released in 1995 Java applications compiled to bytecode (.class files) that can run on any Java virtual machine (JVM) regardless of computer architecture Version History 1 (1995), 2(1998), 3(2000), 4(2002), 5(2004), 6(2006) Java 7 due Q1 2010: No closures ,[object Object],Groovy JRuby (Ruby implementation)	 Scala Clojure (Lisp dialect) Rhino (Javascript implementation) JavaFXScript (Sun’s new baby) Jython (Python implementation)
Tom Corcoran – OSS Software - May 2009 3 Genesis First begun in 2004 by James Strachan, lost momentum, project reenergized by Guillaume Laforgewith v1 released in Jan 2007, currently at v1.6.3 JSR 241: Groovy is an agile, dynamic programming language for the Java Virtual Machine. Groovy includes features found in Python, Ruby, and Smalltalk, but uses syntax similar to the Java programming language Like Java, dynamically compiled to Java Virtual Machine bytecode (.class file) As a result seamless 2 way integration 	with Java code and libraries Deployed as a jar (zip) file
Tom Corcoran – OSS Software - May 2009 4 Java++ Java is a powerful language already,  the goal was to add a new Swiss army  knife to the Java developer tool belt,  to have the agility and expressiveness of a dynamic language Groovy is “quite literally Java, but without the pain” Follows Java semantics, relaxed grammar, derived from java 5 Any Java code will run as Groovy: Its superset-of-Java nature means that you can start with a Java file & change its suffix to  	“.groovy”, often Java developers end up with the  	gradual adoption route which is as designed GDK: extends the JDK (programming tools for Java) Groovyc in addition to javac GroovyDoc in addition to JavaDoc Metaprogramming  Can extend a program at runtime, including changing the structure of objects, types, and behaviour
Tom Corcoran – OSS Software - May 2009 5 Installation Download zip/windows installer & unpack/install Set GROOVY_HOME environment variable to unpacked location Add GROOVY_HOME/bin to your PATH environment variable Set your JAVA_HOME environment variable to point to your JDK Groovy Shell In a command shell type groovysh Run Groovy code groovyMyCode.groovy Groovy Console To run Swing interactive console type GroovyConsole
Tom Corcoran – OSS Software - May 2009 6 GroovyBean
Tom Corcoran – OSS Software - May 2009 7 Increase readability This GroovyBean gives the same result with less code noise This also illustrates a recurring theme in Groovy:  	Make common coding conventions simple def ,[object Object]
 must have def / type name
 defindicates that you don't care about the typesemi colon optional
Tom Corcoran – OSS Software - May 2009 8 Typing Groovy is optionally typed and the Groovy compiler,  groovyc, does not perform full type checking assigning a string to an integer compiles fine, when you try to run you will receive a GroovyCastException exception if you call a method that does not exist, you will not get any compilation error, you will get a MissingMethodException at runtime Rule of thumb: use static typing if interfacing with 	static language code
Tom Corcoran – OSS Software - May 2009 9 Objects & Looping Everything is an object in Groovy Java mixes primitive  Boolean type and the numeric types - byte, short, int, long, and char, float and double  and reference (object) types  class types, interface types, and array types String literals are represented by String objects Looping map A map is a mapping from unique unordered keys to values assert Provide expression that you are asserting will be true, otherwise throws AssertionError new reserved  word
Tom Corcoran – OSS Software - May 2009 10 Regular Expressions Groovy uses the Java regular expression engine but adds some native support sugar ~"pattern" expression, which creates  a Java Pattern object =~ expressions, which creates  a Java Matcher object Slashy strings, can help with escaping
Tom Corcoran – OSS Software - May 2009 11 Groovy Math Groovy uses exact, or decimal math for default calculationsThis means that user computations like: 	1.1 + 0.1 == 1.2 	will return true rather than false (using float or double types  	in Java returns a result of 1.2000000000000002) To achieve this groovy literals with decimal points are instantiated as java.math.BigDecimal types rather than binary floating point types (Float, Double) Some financial users are big fans of how it does Math and I have heard of one where the actuaries are able to code in it too and do as well http://groovy.codehaus.org/Groovy+Math
Tom Corcoran – OSS Software - May 2009 12 Goodies Groovy Truth Groovy provides parsers & slurpers for working with XML Use XmlSlurper to slurp up a xml file
Tom Corcoran – OSS Software - May 2009 13 Goodies+ Optional parameters to achieve this in Java you have you have to overload method Trailing array parameter is optional Implementing interfaces Method parameters optional
Tom Corcoran – OSS Software - May 2009 14 Goodies++ Safe dereferencing Elvis operator is a shortening of Java's ternary operator you will still notice the repetition of the name variable, which  would violate the DRY principle (Don't Repeat Yourself)
Tom Corcoran – OSS Software - May 2009 15 Closures Closures are pieces of code that can augment, refine or enhance another piece of code Closures can be passed to methods GDK Examples
Tom Corcoran – OSS Software - May 2009 16 MOP For each Java class and for each Groovy instance, there is an associated meta-class which represents this runtime behavior of your objects a groovier kind of meta-class is available: the expando meta-class you can check that a certain method or property is available
Tom Corcoran – OSS Software - May 2009 17 MLVM not a silver bullet... Doing at run-time what other languages do at compile time raise the concern of speed of dynamic languages Dynamic languages such as Groovy/JRuby are up to 10 times 	slower on micro benchmarks due to heavy reflection use, this  	does not mean overall speed translates to that ratio the Da Vinci Machine Project Sun project to prototype the extension of the JVM to add 	support for dynamic languages Specification process JSR-292:  Supporting Dynamically Typed Languages add a new bytecode, invokedynamic, to bring dynamic 	language speed closer to 2/3 times of Java may be included in Java 7 http://openjdk.java.net/projects/mlvm/
Tom Corcoran – OSS Software - May 2009 18 Grails & GAE As of 14 May 2009 Grails v1.1.1 now supports the Google Application Engine (GAE) GORM had to have wrapper for GAE’s datastore GQL Up to now to Hosting a grails war was about $20 a month  Now free hosting of application with 500 MB of persistent storage and enough CPU and bandwidth for about 5 million page views a month http://myapplication.appspot.com

Más contenido relacionado

La actualidad más candente

Go language presentation
Go language presentationGo language presentation
Go language presentationparamisoft
 
Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language Ganesh Samarthyam
 
Using Entity Framework's New POCO Features: Part 1, by Julie Lerman
Using Entity Framework's New POCO Features: Part 1, by Julie LermanUsing Entity Framework's New POCO Features: Part 1, by Julie Lerman
Using Entity Framework's New POCO Features: Part 1, by Julie LermanJulie Lerman
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go langAmal Mohan N
 
A First Look at Google's Go Programming Language
A First Look at Google's Go Programming LanguageA First Look at Google's Go Programming Language
A First Look at Google's Go Programming LanguageGanesh Samarthyam
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golangBasil N G
 
ATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming LanguageATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming LanguageJohn Potocny
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventuremylittleadventure
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonpoojakpatel52
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageAniruddha Chakrabarti
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...Mickael Istria
 
Pyconsg2014 pyston
Pyconsg2014 pystonPyconsg2014 pyston
Pyconsg2014 pystonmasahitojp
 
Golang presentaion-2018-07-26
Golang presentaion-2018-07-26Golang presentaion-2018-07-26
Golang presentaion-2018-07-26Shintaro Ikeda
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaDILo Surabaya
 
平行化你的工作 part1
平行化你的工作 part1平行化你的工作 part1
平行化你的工作 part1Shuen-Huei Guan
 
Advantages of Python Learning | Why Python
Advantages of Python Learning | Why PythonAdvantages of Python Learning | Why Python
Advantages of Python Learning | Why PythonEvoletTechnologiesCo
 
Google Go! language
Google Go! languageGoogle Go! language
Google Go! languageAndré Mayer
 

La actualidad más candente (20)

Go language presentation
Go language presentationGo language presentation
Go language presentation
 
Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language
 
Using Entity Framework's New POCO Features: Part 1, by Julie Lerman
Using Entity Framework's New POCO Features: Part 1, by Julie LermanUsing Entity Framework's New POCO Features: Part 1, by Julie Lerman
Using Entity Framework's New POCO Features: Part 1, by Julie Lerman
 
Go lang
Go langGo lang
Go lang
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
A First Look at Google's Go Programming Language
A First Look at Google's Go Programming LanguageA First Look at Google's Go Programming Language
A First Look at Google's Go Programming Language
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
 
ATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming LanguageATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming Language
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventure
 
Introduction to Go-Lang
Introduction to Go-LangIntroduction to Go-Lang
Introduction to Go-Lang
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Go Lang
Go LangGo Lang
Go Lang
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
 
Pyconsg2014 pyston
Pyconsg2014 pystonPyconsg2014 pyston
Pyconsg2014 pyston
 
Golang presentaion-2018-07-26
Golang presentaion-2018-07-26Golang presentaion-2018-07-26
Golang presentaion-2018-07-26
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 
平行化你的工作 part1
平行化你的工作 part1平行化你的工作 part1
平行化你的工作 part1
 
Advantages of Python Learning | Why Python
Advantages of Python Learning | Why PythonAdvantages of Python Learning | Why Python
Advantages of Python Learning | Why Python
 
Google Go! language
Google Go! languageGoogle Go! language
Google Go! language
 

Similar a Tom Corcoran - Introduction to Groovy and Grails - May 2009

Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finessemzgubin
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finessemzgubin
 
JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?Charlie Gracie
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?Charlie Gracie
 
Why don't you Groovy?
Why don't you Groovy?Why don't you Groovy?
Why don't you Groovy?Orest Ivasiv
 
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive MetaprogrammingFeelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive MetaprogrammingMatt Stine
 
GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28Jorge Hidalgo
 
Startup groovysession1
Startup groovysession1Startup groovysession1
Startup groovysession1kyon mm
 
BP203 limitless languages
BP203 limitless languagesBP203 limitless languages
BP203 limitless languagesMark Myers
 
Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVMelliando dias
 
Griffon - Making Swing Fun Again
Griffon - Making Swing Fun AgainGriffon - Making Swing Fun Again
Griffon - Making Swing Fun AgainDanno Ferrin
 
Dsl로 만나는 groovy
Dsl로 만나는 groovyDsl로 만나는 groovy
Dsl로 만나는 groovySeeyoung Chang
 
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovJava 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovSvetlin Nakov
 
Ruby JIT Compilation - Mykhail Bortnyk
Ruby JIT Compilation - Mykhail Bortnyk Ruby JIT Compilation - Mykhail Bortnyk
Ruby JIT Compilation - Mykhail Bortnyk Ruby Meditation
 

Similar a Tom Corcoran - Introduction to Groovy and Grails - May 2009 (20)

Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finesse
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finesse
 
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?
 
JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?
 
Why don't you Groovy?
Why don't you Groovy?Why don't you Groovy?
Why don't you Groovy?
 
Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 
Whats New In Groovy 1.6?
Whats New In Groovy 1.6?Whats New In Groovy 1.6?
Whats New In Groovy 1.6?
 
Golang
GolangGolang
Golang
 
Groovy And Grails
Groovy And GrailsGroovy And Grails
Groovy And Grails
 
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive MetaprogrammingFeelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
 
GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28
 
Startup groovysession1
Startup groovysession1Startup groovysession1
Startup groovysession1
 
BP203 limitless languages
BP203 limitless languagesBP203 limitless languages
BP203 limitless languages
 
Groovy intro
Groovy introGroovy intro
Groovy intro
 
Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVM
 
Griffon - Making Swing Fun Again
Griffon - Making Swing Fun AgainGriffon - Making Swing Fun Again
Griffon - Making Swing Fun Again
 
Dsl로 만나는 groovy
Dsl로 만나는 groovyDsl로 만나는 groovy
Dsl로 만나는 groovy
 
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovJava 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
 
Ruby JIT Compilation - Mykhail Bortnyk
Ruby JIT Compilation - Mykhail Bortnyk Ruby JIT Compilation - Mykhail Bortnyk
Ruby JIT Compilation - Mykhail Bortnyk
 

Tom Corcoran - Introduction to Groovy and Grails - May 2009

  • 1. Tom Corcoran – OSS Software - May 2009 1 Get excited by coding again! Java History & the JVM Groovy genesis & it’s relation to Java Installing Groovy Live demo to compare and contrast Groovy with Java code Groovy Typing Object & Looping Regular Expressions Groovy Math Goodies+++ Closures MOP MLVM Grails & GAE
  • 2.
  • 3. Tom Corcoran – OSS Software - May 2009 3 Genesis First begun in 2004 by James Strachan, lost momentum, project reenergized by Guillaume Laforgewith v1 released in Jan 2007, currently at v1.6.3 JSR 241: Groovy is an agile, dynamic programming language for the Java Virtual Machine. Groovy includes features found in Python, Ruby, and Smalltalk, but uses syntax similar to the Java programming language Like Java, dynamically compiled to Java Virtual Machine bytecode (.class file) As a result seamless 2 way integration with Java code and libraries Deployed as a jar (zip) file
  • 4. Tom Corcoran – OSS Software - May 2009 4 Java++ Java is a powerful language already, the goal was to add a new Swiss army knife to the Java developer tool belt, to have the agility and expressiveness of a dynamic language Groovy is “quite literally Java, but without the pain” Follows Java semantics, relaxed grammar, derived from java 5 Any Java code will run as Groovy: Its superset-of-Java nature means that you can start with a Java file & change its suffix to “.groovy”, often Java developers end up with the gradual adoption route which is as designed GDK: extends the JDK (programming tools for Java) Groovyc in addition to javac GroovyDoc in addition to JavaDoc Metaprogramming Can extend a program at runtime, including changing the structure of objects, types, and behaviour
  • 5. Tom Corcoran – OSS Software - May 2009 5 Installation Download zip/windows installer & unpack/install Set GROOVY_HOME environment variable to unpacked location Add GROOVY_HOME/bin to your PATH environment variable Set your JAVA_HOME environment variable to point to your JDK Groovy Shell In a command shell type groovysh Run Groovy code groovyMyCode.groovy Groovy Console To run Swing interactive console type GroovyConsole
  • 6. Tom Corcoran – OSS Software - May 2009 6 GroovyBean
  • 7.
  • 8. must have def / type name
  • 9. defindicates that you don't care about the typesemi colon optional
  • 10. Tom Corcoran – OSS Software - May 2009 8 Typing Groovy is optionally typed and the Groovy compiler, groovyc, does not perform full type checking assigning a string to an integer compiles fine, when you try to run you will receive a GroovyCastException exception if you call a method that does not exist, you will not get any compilation error, you will get a MissingMethodException at runtime Rule of thumb: use static typing if interfacing with static language code
  • 11. Tom Corcoran – OSS Software - May 2009 9 Objects & Looping Everything is an object in Groovy Java mixes primitive Boolean type and the numeric types - byte, short, int, long, and char, float and double and reference (object) types class types, interface types, and array types String literals are represented by String objects Looping map A map is a mapping from unique unordered keys to values assert Provide expression that you are asserting will be true, otherwise throws AssertionError new reserved word
  • 12. Tom Corcoran – OSS Software - May 2009 10 Regular Expressions Groovy uses the Java regular expression engine but adds some native support sugar ~"pattern" expression, which creates a Java Pattern object =~ expressions, which creates a Java Matcher object Slashy strings, can help with escaping
  • 13. Tom Corcoran – OSS Software - May 2009 11 Groovy Math Groovy uses exact, or decimal math for default calculationsThis means that user computations like: 1.1 + 0.1 == 1.2 will return true rather than false (using float or double types in Java returns a result of 1.2000000000000002) To achieve this groovy literals with decimal points are instantiated as java.math.BigDecimal types rather than binary floating point types (Float, Double) Some financial users are big fans of how it does Math and I have heard of one where the actuaries are able to code in it too and do as well http://groovy.codehaus.org/Groovy+Math
  • 14. Tom Corcoran – OSS Software - May 2009 12 Goodies Groovy Truth Groovy provides parsers & slurpers for working with XML Use XmlSlurper to slurp up a xml file
  • 15. Tom Corcoran – OSS Software - May 2009 13 Goodies+ Optional parameters to achieve this in Java you have you have to overload method Trailing array parameter is optional Implementing interfaces Method parameters optional
  • 16. Tom Corcoran – OSS Software - May 2009 14 Goodies++ Safe dereferencing Elvis operator is a shortening of Java's ternary operator you will still notice the repetition of the name variable, which would violate the DRY principle (Don't Repeat Yourself)
  • 17. Tom Corcoran – OSS Software - May 2009 15 Closures Closures are pieces of code that can augment, refine or enhance another piece of code Closures can be passed to methods GDK Examples
  • 18. Tom Corcoran – OSS Software - May 2009 16 MOP For each Java class and for each Groovy instance, there is an associated meta-class which represents this runtime behavior of your objects a groovier kind of meta-class is available: the expando meta-class you can check that a certain method or property is available
  • 19. Tom Corcoran – OSS Software - May 2009 17 MLVM not a silver bullet... Doing at run-time what other languages do at compile time raise the concern of speed of dynamic languages Dynamic languages such as Groovy/JRuby are up to 10 times slower on micro benchmarks due to heavy reflection use, this does not mean overall speed translates to that ratio the Da Vinci Machine Project Sun project to prototype the extension of the JVM to add support for dynamic languages Specification process JSR-292: Supporting Dynamically Typed Languages add a new bytecode, invokedynamic, to bring dynamic language speed closer to 2/3 times of Java may be included in Java 7 http://openjdk.java.net/projects/mlvm/
  • 20. Tom Corcoran – OSS Software - May 2009 18 Grails & GAE As of 14 May 2009 Grails v1.1.1 now supports the Google Application Engine (GAE) GORM had to have wrapper for GAE’s datastore GQL Up to now to Hosting a grails war was about $20 a month Now free hosting of application with 500 MB of persistent storage and enough CPU and bandwidth for about 5 million page views a month http://myapplication.appspot.com
  • 21. Tom Corcoran – OSS Software - May 2009 19 Resources Groovy http://groovy.codehaus.org Programming Groovy : VenkatSubramaniam Groovy Recipes: Scott Davis Grails http://www.grails.org The Definitive Guide to Grails: Graeme Rocher Grails in Action: Glen Smith & Peter Ledbrook
  • 22. Tom Corcoran – OSS Software - May 2009 20 The End Comments http://joind.in/event/view/46 Local Groovy User Group? http://gugse.com