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
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
81
Android Testing Bootstrap, with Genymotion
eyallezmy
0
150
PlayStore Bashing: Learn from the big fails
eyallezmy
1
96
Android, the life of your app
eyallezmy
2
76
Build a User Experience on Android
eyallezmy
1
81
Secure your app, fight the leaks!
eyallezmy
0
48
Other Decks in Programming
See All in Programming
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
890
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
220
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
110
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
370
Heart of Swift Concurrency
koher
0
250
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
290
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
270
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
240
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
150
自分的「カンファレンスの楽しみ方」
syumai
0
200
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
140
Featured
See All Featured
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
Accessibility Awareness
sabderemane
1
210
We Are The Robots
honzajavorek
0
360
The World Runs on Bad Software
bkeepers
PRO
72
12k
Technical Leadership for Architectural Decision Making
baasie
3
560
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
500
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
330
Large-scale JavaScript Application Architecture
addyosmani
515
110k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
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