SlideShare a Scribd company logo
1 of 49
Download to read offline
Fly Through
Who?
<niklas.lindstrom@valtech.se>
@niklasl
Trust me?
Used dynamic langs on the JVM since 2000.
Groovy since 2004/2007
What?
A Dynamic Language for the JVM
A modern language
Inspired by best features:
Java
Ruby
Python
Smalltalk
...
Java
The Premise
The Platform
Exciting?
Modern GC
JIT
Puts hardware to good use
(mem, multi-core, I/O)
Java = Community
Well-established libraries (jdk, commons, ...).
Loads of opens source stuff.
Evolution
Groovy extends Java.
Really. 100% semantically, 90% syntactically.
Creative
Tools
What does it look like?
class First {
static void main(String[] args) {
println "You just gave me " + args[0]
}
}
Shorter
println "You just gave me ${args[0]}"
Many Variants
class Think {
String value
def getMeaning() {
"You just gave me ${value}."
}
static main(args) {
def first = args? args[0] : "nothing"
println new Think(value:first).meaning
}
}
Usages
Everywhere.
Groovy classes are real classes in Java.
Cherry-pick
● Small scripts
● API experimentation
● Tools for batch and analysis
● Tests, Specs
● Building
Entire applications
Seamlessly cross-compiles with Java.
Write any or all parts in Groovy, using any Java
framework.
Ceremony
public class Item {
private String name;
private String description;
public Item() {}
public String getName() { return name; }
public String setName(String name) {
this.name = name;
}
public String getDescription() { return description; }
public void setDescription(String description) {
this.description = description;
}
}
Pragmatic
class Item {
String name
String description
}
Compact Properties
new Date().time // same as getTime()
Dynamic
def v = "string.."
v = 1
assert v instanceof String
No cast needed
Just access methods and properties expected to
be there.
But..
Types have significance..
Type Hybrid
Dynamic refs are declared with def.
Typed refs are auto-cast & converted:
String v = 123
v.bytes[-1] == '3'
GroovyCastException
Date d
d = "hi!"
Small Values of Cool
Optional Parens
client.sendMessage "Message: ${msg}"
client.quit()
Access else null
response?.entity
Use all
files*.name
Slice
def l = ['a', 'b', 'c', 'd']
assert l[1..-2] == ['b', 'c']
Map Expandos
Map map = ['a': 1, b: 2]
assert map['a'] == 1
assert map.b == 2
map.c = 3
map['d'] = 3
assert map['c'] == map.d
Closures
Code block literals.
Syntax:
def items = ["a", "b", "c", "def"]
items.eachWithIndex { item, i ->
println "${i+1}: ${item}"
}
Sift and Transform
def values = ["1", "2", "12", "123"]
def some = values.findAll { it.size() > 1 }
def ints = some.collect { (it as int) * 2 }
assert ints == [24, 246]
GDK
new File("urls.txt").eachLine {
def url = new URL(it)
def file = new File("./${url.path}")
file.parentFile.mkdirs()
file.bytes = url.bytes
}
Xml...
def slurper = new XmlSlurper()
def html = slurper.parse(new File("/some.xhtml"))
html.body.'*'.each {
println it.'@id'
}
Spock
def "lists should be appendable"() {
given:
def a = []
when:
a << 1
then:
a == [1]
}
Mocks
EventHandler handler = Mock()
handler.handle(someAllowedEvent) >> true
handler.handle(_) >> false
Data-driven
expect:
a.toUpperCase() == b
where:
a | b
"a" | "A"
"b" | "B"
"c" | "C"
"d" | "D"
PowerAsserts
assert a == [1]
ERROR org.codehaus.groovy.tr...rt.PowerAssertionError:
assert a == [1]
| |
| false
[]
Environments
Scripts
$ groovy setup_db.groovy
REPL
$ groovysh
groovy:000> import org.apache.commons.io.*
Groovy Console
Building
Ant
Maven
Gradle
Grab with Grape
@Grab('org.mortbay.jetty:jetty-embedded:6.1.0')
import org.mortbay.jetty.Server
def server = new Server(8080)
server.start()
IDE:s
Amazing IntelliJ support.
Eclipse known to be good..
The Power of Prototyping
"You can use Groovy as
an exploratory language
for functionality spikes."
More Info
<http://groovy.codehaus.org/>
<http://spockframework.org/>
.. the web is full of groovy:
<http://groovyconsole.appspot.com/>
Groovy Style For the Java Guy
Thank you!
CC Images
Groovy-logo, "Groovy Duke"
"Tools"
"Shell"
"Tadpole"

More Related Content

What's hot

Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Remy Sharp
 
GR8Conf 2011: GContracts
GR8Conf 2011: GContractsGR8Conf 2011: GContracts
GR8Conf 2011: GContracts
GR8Conf
 

What's hot (20)

Guaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in RustGuaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in Rust
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlin
 
Intro to Rust from Applicative / NY Meetup
Intro to Rust from Applicative / NY MeetupIntro to Rust from Applicative / NY Meetup
Intro to Rust from Applicative / NY Meetup
 
Gpu programming with java
Gpu programming with javaGpu programming with java
Gpu programming with java
 
Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)
 
Python lec4
Python lec4Python lec4
Python lec4
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
iOS Development with Blocks
iOS Development with BlocksiOS Development with Blocks
iOS Development with Blocks
 
Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Ns2programs
Ns2programsNs2programs
Ns2programs
 
Introduce to Rust-A Powerful System Language
Introduce to Rust-A Powerful System LanguageIntroduce to Rust-A Powerful System Language
Introduce to Rust-A Powerful System Language
 
Rust vs C++
Rust vs C++Rust vs C++
Rust vs C++
 
Python lec5
Python lec5Python lec5
Python lec5
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Introduction to CUDA C: NVIDIA : Notes
Introduction to CUDA C: NVIDIA : NotesIntroduction to CUDA C: NVIDIA : Notes
Introduction to CUDA C: NVIDIA : Notes
 
OPTIMAL BINARY SEARCH
OPTIMAL BINARY SEARCHOPTIMAL BINARY SEARCH
OPTIMAL BINARY SEARCH
 
GR8Conf 2011: GContracts
GR8Conf 2011: GContractsGR8Conf 2011: GContracts
GR8Conf 2011: GContracts
 
C++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingC++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogramming
 

Viewers also liked

#SMiLELondon Pearson
#SMiLELondon Pearson #SMiLELondon Pearson
#SMiLELondon Pearson
Marc Wright
 
University Ready? Task 2 - Reading Like You've Never Read Before
University Ready? Task 2 - Reading Like You've Never Read BeforeUniversity Ready? Task 2 - Reading Like You've Never Read Before
University Ready? Task 2 - Reading Like You've Never Read Before
Elisabeth Chan
 

Viewers also liked (8)

#SMiLELondon Pearson
#SMiLELondon Pearson #SMiLELondon Pearson
#SMiLELondon Pearson
 
تويتر لاستخدام التواصل الاجتماعي
تويتر لاستخدام التواصل الاجتماعي تويتر لاستخدام التواصل الاجتماعي
تويتر لاستخدام التواصل الاجتماعي
 
Lee Stevens sharepoint 2010
Lee Stevens   sharepoint 2010Lee Stevens   sharepoint 2010
Lee Stevens sharepoint 2010
 
Something Specific and Simple
Something Specific and SimpleSomething Specific and Simple
Something Specific and Simple
 
Blog & Electronic Press التدوين و الصحافة الإلكترونية
Blog & Electronic Press التدوين و الصحافة الإلكترونية  Blog & Electronic Press التدوين و الصحافة الإلكترونية
Blog & Electronic Press التدوين و الصحافة الإلكترونية
 
University Ready? Task 2 - Reading Like You've Never Read Before
University Ready? Task 2 - Reading Like You've Never Read BeforeUniversity Ready? Task 2 - Reading Like You've Never Read Before
University Ready? Task 2 - Reading Like You've Never Read Before
 
(first '(Clojure.))
(first '(Clojure.))(first '(Clojure.))
(first '(Clojure.))
 
Länkad Data
Länkad DataLänkad Data
Länkad Data
 

Similar to Groovy Fly Through

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
Garth Gilmour
 

Similar to Groovy Fly Through (20)

Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Groovy!
Groovy!Groovy!
Groovy!
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume LaforgeGroovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
 
Latinoware
LatinowareLatinoware
Latinoware
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Groovy intro for OUDL
Groovy intro for OUDLGroovy intro for OUDL
Groovy intro for OUDL
 
Dart, unicorns and rainbows
Dart, unicorns and rainbowsDart, unicorns and rainbows
Dart, unicorns and rainbows
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
Javascript status 2016
Javascript status 2016Javascript status 2016
Javascript status 2016
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentation
 
Groovy
GroovyGroovy
Groovy
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Groovy
GroovyGroovy
Groovy
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Groovy Fly Through