Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
From Java to Groovy, the easy way
Search
Eyal LEZMY
December 22, 2014
Programming
120
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
From Java to Groovy, the easy way
This short presentation introduces to the Groovy language, coming from Java.
Eyal LEZMY
December 22, 2014
More Decks by Eyal LEZMY
See All by Eyal LEZMY
Gradle plugins, take it to the next level
eyallezmy
1
110
Gradle Plugin, take the control of the build!
eyallezmy
1
230
(Bitchy) App Clinic - Microsoft XIM
eyallezmy
0
79
Android Testing Bootstrap, with Genymotion
eyallezmy
0
140
PlayStore Bashing: Learn from the big fails
eyallezmy
1
88
Android, the life of your app
eyallezmy
2
72
Build a User Experience on Android
eyallezmy
1
80
Secure your app, fight the leaks!
eyallezmy
0
45
Other Decks in Programming
See All in Programming
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
180
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
4
630
AI時代のUIはどこへ行く?その2!
yusukebe
19
6.9k
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
280
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.3k
AIエージェントと協働するCLI開発 — BunとOpenClawで学んだこと
yoshikouki
1
240
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
630
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
230
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
100
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
3
140
Swiftのレキシカルスコープ管理
kntkymt
0
220
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
460
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
200
The Limits of Empathy - UXLibs8
cassininazir
1
350
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
300
GraphQLとの向き合い方2022年版
quramy
50
15k
YesSQL, Process and Tooling at Scale
rocio
174
15k
First, design no harm
axbom
PRO
2
1.2k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
160
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
320
Transcript
From Java to Groovy The easy way
Eyal LEZMY http://eyal.fr SLIDES http://bit.ly/JA2GR
What’s Groovy? Alternative language for the JVM Compiles bytecode Statically
or at Runtime Can use Java libraries
From Java to Groovy 01 by Guillaume Laforge
public class HelloWorld { private String name; public void setName(String
name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println( helloWorld.greet() ); } } From JAVA
public class HelloWorld { private String name; public void setName(String
name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println( helloWorld.greet() ); } } To GROOVY
public class HelloWorld { private String name; public void setName(String
name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println( helloWorld.greet() ); } } To GROOVY
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello " + name } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello " + name } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello ${name}" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello ${name}" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY GString => double quotes (“ ”)
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello $name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello $name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello $name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY Private field
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello $name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY Getter & Setter Private field
class HelloWorld { private String name void setName(String name) {
this.name = name } String getName() { return name } String greet() { return "Hello $name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.setName("Groovy") System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.name = "Groovy" System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.name = "Groovy" System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.name = "Groovy" System.out.println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.name = "Groovy" println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.name = "Groovy" println( helloWorld.greet() ) } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.name = "Groovy" println helloWorld.greet() } } To GROOVY
class HelloWorld { String name String greet() { return "Hello
$name" } static void main(String[] args) { HelloWorld helloWorld = new HelloWorld() helloWorld.name = "Groovy" println helloWorld.greet() } } To GROOVY
class HelloWorld { def name def greet() { return "Hello
$name" } static main(args) { def helloWorld = new HelloWorld() helloWorld.name = "Groovy" println helloWorld.greet() } } To GROOVY
class HelloWorld { def name def greet() { return "Hello
$name" } static main(args) { def helloWorld = new HelloWorld() helloWorld.name = "Groovy" println helloWorld.greet() } } To GROOVY
class HelloWorld { def name def greet() { return "Hello
$name" } static main(args) { def helloWorld = new HelloWorld() helloWorld.name = "Groovy" println helloWorld.greet() } } To GROOVY
class HelloWorld { def name def greet() { return "Hello
$name" } } def helloWorld = new HelloWorld() helloWorld.name = "Groovy" println helloWorld.greet() To GROOVY
public class HelloWorld { private String name; public void setName(String
name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println( helloWorld.greet() ); } } From JAVA
Where the Magic happens... 02
Methods Default value parameters Named parameters No return statement Return
multiple variables Groovy Methods
def createGenyboy(gender = “male”) { … if(gender == “male”) name
= “Genyboy” … [name, color, size] } def(String name, Color color, int size) = createGenyboy(gender:“female”) Groovy Methods
static def cmd(def command, Closure c){ Process p = command.execute()
p.text.eachLine {line, count -> c(line, count) } p.exitValue() } a = “hello” cmd(“gmtool admin list”) {line, count -> print a + line } Groovy Closures
def array = [] array = [“one”, “two”, “three”] tab.findAll(){item
-> item.size == 3 print it } [1, 2, 3].each(){ print it } def map = [:] map = [one:1, two:2, three:3] assert map.one == map[“one”] def range = 2..5 assert range == [2, 3, 4, 5] Groovy Collections
static noNull(Closure c){ String nullLabel = null.toString() NullObject.metaClass.toString = {return
''} c() //set as defaut NullObject.metaClass.toString = {return nullLabel} } cmd([“gmtool”, “admin”, “create” “template”, “device”, “--density=”+density]) >> gmtool admin create template device --density=null noNull{ cmd([“gmtool”, “admin”, “create” “template”, “device”, “--density=”+density]) } >> gmtool admin create template device --density= Groovy Metaclass
boolean checkTable(tab) { if(tab?.size() >= 4) return true return false
} Groovy Safe Navigation
And others Native support for Regex ~/myRegex/ Powerful switch statement
switch awesomness { case 1..10: “yeah!” } Operator Overloading 1 + 1 = 1
Conclusion You keep focus on business logic Like magic So
dynamic, you have to test ! JUnit & Co. So dynamic, so easy to mock JSON-likery
References From Java to Groovy http://groovy.dzone.com/news/java-groovy-few-easy-steps By Guillaume Laforge Differences
from Java http://groovy.codehaus.org/Differences+from+Java Official documentation http://groovy.codehaus.org/
Thank you for your time ! http://eyal.fr SLIDES http://bit.ly/JA2GR