Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Introduction to Groovy
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kevin Tan
September 16, 2014
Programming
66
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Groovy
Introduction to Groovy, the next generation JVM programming language
Kevin Tan
September 16, 2014
More Decks by Kevin Tan
See All by Kevin Tan
JVM Web Frameworks Exploration
s1lv3rd3m0n
0
41
Groovy on Google App Engine with Gaelyk
s1lv3rd3m0n
0
120
Other Decks in Programming
See All in Programming
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
JIS keyboard support in Omarchy
lef237
0
110
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
210
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
ChromeでローカルLLM
ryu1013
0
140
golang-bob.pdf
iwatsukayura
0
130
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
0
1.2k
最近”作らせてる” ローカルAIアプリの話
akit37
0
470
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
890
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Featured
See All Featured
Amusing Abliteration
ianozsvald
1
350
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
My Coaching Mixtape
mlcsv
0
360
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
GraphQLとの向き合い方2022年版
quramy
50
15k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
800
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Paper Plane
katiecoart
PRO
5
54k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Code Reviewing Like a Champion
maltzj
529
40k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Transcript
Introduction to Groovy The next generation JVM programming language
What is Groovy? • Scripting language • Programming Language •
runs on JVM • dynamic • derived from Java • JSR-241 • started from 2003
Problem with Java • Primitive data types, defies the nature
of OO programming
Why Groovy • Easier than Java syntax • Fully compatible
with Java • Easy to find workarounds since Java code can be compiled • Principle of least surprises
Use Cases • Scripting instead of Sh, Perl, Python, Ruby,
etc • Simpler ways of writing unit tests, stub and mocks • Configuration/Dependency Management in Gradle ! • Full blown applications via Grails and Griffon
Groovy Features Everything is an object, including numbers Example: 5.times{
println “ho” } (NOTE: Curly braces is a Closure)
Groovy Features • Dynamic data type / Explicit typing def
b = 2 def is a reference, asks the compiler to figure out for itself.
Groovy Features • Objects new User(name: ‘Kevin’, email:’
[email protected]
’)
Groovy Features • Collections New collection type - Range Eg.
1..5 (inclusive, range from 1 to 5) or 1..<5 (exclusive, range from 1 to 4)
Groovy Features • Collections Iterator, eg. r.each { n-> println
n } or r.each { println it } (where ‘it’ is a reserved word)
Groovy Features • Syntactic sugar for List def countries =
[“Malaysia”, “Thailand”]
Groovy Features • Adding or removing values list += “Singapore”
becomes [“Malaysia”, “Thailand”, “Singapore”] ! list = list - [“Singapore”] becomes [“Malaysia”, “Thailand”]
Groovy Features Map def person = [name:”Kevin”, age:”27”]! println person.name
<- how you access the value
Groovy Features • New for loop syntax for(i in 1..5){!
println i! }! but Java loop syntax is supported anyways.
Groovy Features Operator overloading a + b (Java) becomes a.plus(b)
(Groovy) a++ or ++a (Java) becomes a.next() (Groovy) switch(a) { case b: } becomes b.isCase(a) More info: http://groovy.codehaus.org/Operator+Overloading
Groovy Features • Switch statement is more general than Java,
eg: switch (val) { case it > 3: break case 5..9: break case Number: break }
Groovy Features • Groovy Truth standard conditional operators on boolean
expressions & boolean expressions for collections (empty collections = false)
Groovy Features • Groovy Truth Applies for Maps, iterations and
enums, objects, numbers ! http://groovy.codehaus.org/Groovy+Truth
Groovy Features • Closures : High Order Functions Idea :
Methods are like objects, anonymous class in steroids Treated as a “code block” to be executed later, eg. def testClosure = { println “test closure” }
Groovy Features • Closures : High Order Functions with parameters
eg. def methodName = { n, r -> … do something } To call the method, method(n, r)
Groovy Features • File I/O def count=0, MAXSIZE=100 new File("foo.txt").withReader
{ reader -> while (reader.readLine() != null) { if (++count > MAXSIZE) throw new RuntimeException('File too large!') } }
Groovy Features • File I/O def fields = ["a":"1", "b":"2",
"c":"3"] new File("foo.ini").withWriter { out -> fields.each() { key, value -> out.writeLine("${key}=${value}") } }
More References • Groovy http://groovy.codehaus.org • Grails (www.grails.org) for Web
development • Griffon (www.griffon.org) for desktop app development
Contacts • http://gplus.to/kevintanhongann