SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
Groovify your Java Code
A guide to Groovy syntax for Java coders
By for Coding Dojo 2014
Interactive slides at:
Hervé Vũ Roussel Agile Vietnam
https://slides.com/hroussel/groovify-your-java-code
Print / bracket, semicol optional
System.out.println("Hello World!");
println "Hello World!"
Return optional
String getCurrentCity() {
return "Ho Chi Minh City";
}
def getCurrentCity() {
"Ho Chi Minh City"
}
Try/catch optional
try{
Reader reader = new FileReader("/vietnam-cities.txt")
}
catch(FileNotFoundException e) {
e.printStackTrace()
}
def reader = new FileReader("/vietnam-cities.txt")
Duck typing
String s = "Hello";
String c = 'c';
Integer i = new Integer(1);
BigDecimal d = new BigDecimal(1.2);
def s = "Hello"
def c = 'c'
def i = 1
def d = 1.2
Strong typing
String s = "Hello";
Character = new Character(‘c’);
Integer i = new Integer(1);
Float d = new Float(1.2);
String s = "Hello"
Character c = 'c'
Integer i = 1
Float f = 1.2
Existential operator (Elvis)
if (city != null) {
if (city.getAirport() != null) {
city.getAirport().getCode();
}
}
city?.getAirport()?.getCode()
Truth
if (1 != 0)
if (new City() != null)
if ("John".equals(""))
if (["HCMC", "Hanoi"].length > 0)
if (1)
if (city)
if ("John")
if (["HCMC", "Hanoi"])
Collections
String [] cities = ["HCMC","Hanoi"];
System.out.println(cities[0]);
Map<String,String> airports = new HashMap<String,String>();
airports.put("SGN", "Ho Chi Minh City");
airports.put("CDG", "Paris");
System.out.println(airports.get("SGN"));
def cities = ["HCMC","Hanoi"]
println cities[0]
def airports = [SGN:"Ho Chi Minh City", CDG:"Paris"]
println airports.SGN
Ranges
List<String> alphabet = new ArrayList<String>();
for(int i=0;i<26;i++) {
alphabet.add(Character.toChars(i+97));
}
def alphabet = "a".."z"
GString
System.out.println("Hello " + user.name);
println "Hello ${user.name}"
Groovy Scripts
public class Script1 {
public static void main(String[] args){
String greeting = "Hello " + args[0];
System.out.println(greeting);
}
}
greeting = "Hello ${args[0]}"
println greeting
POGOs
public class City {
private String name;
public String getName() {
return this.name;
}
public String setName(String name) {
this.name = name;
}
}
System.out.println(new City("HCMC").getName());
class City {
String name
}
println new City(name: "HCMC").name
Compare objects
a.equals(b);
a.compareTo(b);
a == b
a < b
Default parameters
public class Trip {
public Trip(String source, String dest, String type) {
if (type == null)
this.type = "Car";
}
}
new Trip("HCMC", "Vung Tau", null);
class Trip {
Trip(String source, String dest, String type = "Car") {
this.type = type;
}
}
new Trip("HCMC", "Vung Tau")
Closures
List result = new ArrayList();
for(city in city) {
if (city.startsWith("H")
result.add(city)
}
cities.findAll { it.startsWith("H") }
Closures (cont.)
​class City {
String name
}
def cities = [
new City(name: "Mui Ne"),
new City(name: "Hanoi")
]
cities.collect { it.name + ", VN" } ==
[ "Mui Ne, VN", "Hanoi, VN" ]
cities.any { it.name.indexOf(" ") != -1 } == true
cities.every { it.name.indexOf(" ") == -1 } == false
cities.find { it.name.startsWith("H") }.name == "Hanoi"
The End
More on Groovy:
Book: (I didn't write it!)
Slides:
Interactive:
PDF:
Thank you!
Free: Groovy User Guide
Groovy Recipes: Greasing the Wheels of Java
Online compiler/runner
http://slides.com/hroussel
https://www.slideshare.net/hroussel
Hervé Vũ Roussel
http://herveroussel.com
Groovify your Java CodeA guide to Groovy syntax for Java coders By Hervé Vũ Roussel for Agile
Vietnam Coding Dojo 2014 Interactive slides at: https://slides.com/hroussel/groovify-your-java-code
Groovify your Java code
Edit deck title & description
a day ago 0 68
Hervé Roussel
http://www.herveroussel.com hvroussel
0
Tweet 0
0
Like
We were unable to load Disqus. If you are a moderator please see our troubleshooting guide
0 Comments Slides
Disqus
Faceb
Twitte
Googl
Login
Newest
Oldest
Sort by Best
Best
Share
Share this discussion on
Start the discussion…

Más contenido relacionado

La actualidad más candente (20)

block introduce
block introduceblock introduce
block introduce
 
Groovyノススメ
GroovyノススメGroovyノススメ
Groovyノススメ
 
Hotel Management In C++
Hotel Management In C++Hotel Management In C++
Hotel Management In C++
 
ClojureScript - A functional Lisp for the browser
ClojureScript - A functional Lisp for the browserClojureScript - A functional Lisp for the browser
ClojureScript - A functional Lisp for the browser
 
Go for Rubyists
Go for RubyistsGo for Rubyists
Go for Rubyists
 
Code
CodeCode
Code
 
Tools.cpp
Tools.cppTools.cpp
Tools.cpp
 
1
11
1
 
Functional Reactive Programming
Functional Reactive ProgrammingFunctional Reactive Programming
Functional Reactive Programming
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional Programming
 
C++ programs
C++ programsC++ programs
C++ programs
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
C++totural file
C++totural fileC++totural file
C++totural file
 
Tugas Program C++
Tugas Program C++Tugas Program C++
Tugas Program C++
 
งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์
 
Functional programming with Immutable .JS
Functional programming with Immutable .JSFunctional programming with Immutable .JS
Functional programming with Immutable .JS
 
Do while loop
Do while loopDo while loop
Do while loop
 
completion_proc and history
completion_proc and historycompletion_proc and history
completion_proc and history
 
Conversion of data types in java
Conversion of data types in javaConversion of data types in java
Conversion of data types in java
 

Destacado

Code fast & Break things with Jenkins & Continuous Integration
Code fast & Break things with Jenkins & Continuous IntegrationCode fast & Break things with Jenkins & Continuous Integration
Code fast & Break things with Jenkins & Continuous IntegrationHervé Vũ Roussel
 
Pelican Cays 2003 To 2007 Paradise Cove
Pelican Cays 2003 To 2007 Paradise CovePelican Cays 2003 To 2007 Paradise Cove
Pelican Cays 2003 To 2007 Paradise Covekennedykiwi
 
Old Guard Presentation
Old Guard PresentationOld Guard Presentation
Old Guard PresentationBobby.Lindsey
 
3 lessons i learned from building a killer start up
3 lessons i learned from building a killer start up3 lessons i learned from building a killer start up
3 lessons i learned from building a killer start upHervé Vũ Roussel
 
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...How I learned to stop worrying and love the bugs with Jenkins & Continuous In...
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...Hervé Vũ Roussel
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Hervé Vũ Roussel
 
หนังสือ Yii Framework Application Workshop เล่ม 1
หนังสือ Yii Framework Application Workshop เล่ม 1หนังสือ Yii Framework Application Workshop เล่ม 1
หนังสือ Yii Framework Application Workshop เล่ม 1Manop Kongoon
 
หนังสือ Yii framework 2 Web Application Basic ฉบับพื้นฐาน
หนังสือ Yii framework 2 Web Application Basic ฉบับพื้นฐานหนังสือ Yii framework 2 Web Application Basic ฉบับพื้นฐาน
หนังสือ Yii framework 2 Web Application Basic ฉบับพื้นฐานManop Kongoon
 
หนังสือ Yii framework Tip 50 เทคนิค Yii Framework
หนังสือ Yii framework Tip 50 เทคนิค Yii Frameworkหนังสือ Yii framework Tip 50 เทคนิค Yii Framework
หนังสือ Yii framework Tip 50 เทคนิค Yii FrameworkManop Kongoon
 
Yii framework 2 basic training
Yii framework 2 basic trainingYii framework 2 basic training
Yii framework 2 basic trainingManop Kongoon
 
HTML PHP MySQL สำหรับเว็บโปรแกรมเมอร์มือใหม่
HTML PHP MySQL สำหรับเว็บโปรแกรมเมอร์มือใหม่HTML PHP MySQL สำหรับเว็บโปรแกรมเมอร์มือใหม่
HTML PHP MySQL สำหรับเว็บโปรแกรมเมอร์มือใหม่Manop Kongoon
 
The Climate Challenge: Saving Ourselves
The Climate Challenge: Saving OurselvesThe Climate Challenge: Saving Ourselves
The Climate Challenge: Saving OurselvesSustento
 
Envisaging the future
Envisaging the futureEnvisaging the future
Envisaging the futureSustento
 
Developing a resilient money system
Developing a resilient money systemDeveloping a resilient money system
Developing a resilient money systemSustento
 
Defusing the debt bomb talk
Defusing the debt bomb talk Defusing the debt bomb talk
Defusing the debt bomb talk Sustento
 
Human Capital as 21st Century Infrastructure
Human Capital as 21st Century Infrastructure Human Capital as 21st Century Infrastructure
Human Capital as 21st Century Infrastructure Sustento
 

Destacado (20)

Code fast & Break things with Jenkins & Continuous Integration
Code fast & Break things with Jenkins & Continuous IntegrationCode fast & Break things with Jenkins & Continuous Integration
Code fast & Break things with Jenkins & Continuous Integration
 
Pelican Cays 2003 To 2007 Paradise Cove
Pelican Cays 2003 To 2007 Paradise CovePelican Cays 2003 To 2007 Paradise Cove
Pelican Cays 2003 To 2007 Paradise Cove
 
Old Guard Presentation
Old Guard PresentationOld Guard Presentation
Old Guard Presentation
 
Offline First with CouchDB
Offline First with CouchDBOffline First with CouchDB
Offline First with CouchDB
 
GW SDAB Dev Tools 2012
GW SDAB Dev Tools 2012GW SDAB Dev Tools 2012
GW SDAB Dev Tools 2012
 
3 lessons i learned from building a killer start up
3 lessons i learned from building a killer start up3 lessons i learned from building a killer start up
3 lessons i learned from building a killer start up
 
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...How I learned to stop worrying and love the bugs with Jenkins & Continuous In...
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS
 
หนังสือ Yii Framework Application Workshop เล่ม 1
หนังสือ Yii Framework Application Workshop เล่ม 1หนังสือ Yii Framework Application Workshop เล่ม 1
หนังสือ Yii Framework Application Workshop เล่ม 1
 
หนังสือ Yii framework 2 Web Application Basic ฉบับพื้นฐาน
หนังสือ Yii framework 2 Web Application Basic ฉบับพื้นฐานหนังสือ Yii framework 2 Web Application Basic ฉบับพื้นฐาน
หนังสือ Yii framework 2 Web Application Basic ฉบับพื้นฐาน
 
หนังสือ Yii framework Tip 50 เทคนิค Yii Framework
หนังสือ Yii framework Tip 50 เทคนิค Yii Frameworkหนังสือ Yii framework Tip 50 เทคนิค Yii Framework
หนังสือ Yii framework Tip 50 เทคนิค Yii Framework
 
Yii framework 2 basic training
Yii framework 2 basic trainingYii framework 2 basic training
Yii framework 2 basic training
 
HTML PHP MySQL สำหรับเว็บโปรแกรมเมอร์มือใหม่
HTML PHP MySQL สำหรับเว็บโปรแกรมเมอร์มือใหม่HTML PHP MySQL สำหรับเว็บโปรแกรมเมอร์มือใหม่
HTML PHP MySQL สำหรับเว็บโปรแกรมเมอร์มือใหม่
 
The Climate Challenge: Saving Ourselves
The Climate Challenge: Saving OurselvesThe Climate Challenge: Saving Ourselves
The Climate Challenge: Saving Ourselves
 
Sierra Club Pro
Sierra Club ProSierra Club Pro
Sierra Club Pro
 
Envisaging the future
Envisaging the futureEnvisaging the future
Envisaging the future
 
Portfolio Slides
Portfolio SlidesPortfolio Slides
Portfolio Slides
 
Developing a resilient money system
Developing a resilient money systemDeveloping a resilient money system
Developing a resilient money system
 
Defusing the debt bomb talk
Defusing the debt bomb talk Defusing the debt bomb talk
Defusing the debt bomb talk
 
Human Capital as 21st Century Infrastructure
Human Capital as 21st Century Infrastructure Human Capital as 21st Century Infrastructure
Human Capital as 21st Century Infrastructure
 

Similar a Groovify your java code by hervé roussel

Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor Ivry
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistAnton Arhipov
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis Vendrame
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistAnton Arhipov
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)ThomasHorta
 
Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in GroovyGanesh Samarthyam
 
Speed up the mobile development process
Speed up the mobile development processSpeed up the mobile development process
Speed up the mobile development processLeonardoSarra
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Chang W. Doh
 
Riga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistRiga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistAnton Arhipov
 
iOS Talks 1 - CodeCamp Osijek - Swift u praksi
iOS Talks 1 - CodeCamp Osijek - Swift u praksiiOS Talks 1 - CodeCamp Osijek - Swift u praksi
iOS Talks 1 - CodeCamp Osijek - Swift u praksiMarin Benčević
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsAlfonso Peletier
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsJigar Gosar
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agentsRafael Winterhalter
 

Similar a Groovify your java code by hervé roussel (20)

Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with Javassist
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)
 
Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in Groovy
 
Speed up the mobile development process
Speed up the mobile development processSpeed up the mobile development process
Speed up the mobile development process
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요
 
Riga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistRiga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with Javassist
 
iOS Talks 1 - CodeCamp Osijek - Swift u praksi
iOS Talks 1 - CodeCamp Osijek - Swift u praksiiOS Talks 1 - CodeCamp Osijek - Swift u praksi
iOS Talks 1 - CodeCamp Osijek - Swift u praksi
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
P2
P2P2
P2
 

Último

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
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 Processorsdebabhi2
 
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, Adobeapidays
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Groovify your java code by hervé roussel

  • 1. Groovify your Java Code A guide to Groovy syntax for Java coders By for Coding Dojo 2014 Interactive slides at: Hervé Vũ Roussel Agile Vietnam https://slides.com/hroussel/groovify-your-java-code
  • 2. Print / bracket, semicol optional System.out.println("Hello World!"); println "Hello World!"
  • 3. Return optional String getCurrentCity() { return "Ho Chi Minh City"; } def getCurrentCity() { "Ho Chi Minh City" }
  • 4. Try/catch optional try{ Reader reader = new FileReader("/vietnam-cities.txt") } catch(FileNotFoundException e) { e.printStackTrace() } def reader = new FileReader("/vietnam-cities.txt")
  • 5. Duck typing String s = "Hello"; String c = 'c'; Integer i = new Integer(1); BigDecimal d = new BigDecimal(1.2); def s = "Hello" def c = 'c' def i = 1 def d = 1.2
  • 6. Strong typing String s = "Hello"; Character = new Character(‘c’); Integer i = new Integer(1); Float d = new Float(1.2); String s = "Hello" Character c = 'c' Integer i = 1 Float f = 1.2
  • 7. Existential operator (Elvis) if (city != null) { if (city.getAirport() != null) { city.getAirport().getCode(); } } city?.getAirport()?.getCode()
  • 8. Truth if (1 != 0) if (new City() != null) if ("John".equals("")) if (["HCMC", "Hanoi"].length > 0) if (1) if (city) if ("John") if (["HCMC", "Hanoi"])
  • 9. Collections String [] cities = ["HCMC","Hanoi"]; System.out.println(cities[0]); Map<String,String> airports = new HashMap<String,String>(); airports.put("SGN", "Ho Chi Minh City"); airports.put("CDG", "Paris"); System.out.println(airports.get("SGN")); def cities = ["HCMC","Hanoi"] println cities[0] def airports = [SGN:"Ho Chi Minh City", CDG:"Paris"] println airports.SGN
  • 10. Ranges List<String> alphabet = new ArrayList<String>(); for(int i=0;i<26;i++) { alphabet.add(Character.toChars(i+97)); } def alphabet = "a".."z"
  • 11. GString System.out.println("Hello " + user.name); println "Hello ${user.name}"
  • 12. Groovy Scripts public class Script1 { public static void main(String[] args){ String greeting = "Hello " + args[0]; System.out.println(greeting); } } greeting = "Hello ${args[0]}" println greeting
  • 13. POGOs public class City { private String name; public String getName() { return this.name; } public String setName(String name) { this.name = name; } } System.out.println(new City("HCMC").getName()); class City { String name } println new City(name: "HCMC").name
  • 15. Default parameters public class Trip { public Trip(String source, String dest, String type) { if (type == null) this.type = "Car"; } } new Trip("HCMC", "Vung Tau", null); class Trip { Trip(String source, String dest, String type = "Car") { this.type = type; } } new Trip("HCMC", "Vung Tau")
  • 16. Closures List result = new ArrayList(); for(city in city) { if (city.startsWith("H") result.add(city) } cities.findAll { it.startsWith("H") }
  • 17. Closures (cont.) ​class City { String name } def cities = [ new City(name: "Mui Ne"), new City(name: "Hanoi") ] cities.collect { it.name + ", VN" } == [ "Mui Ne, VN", "Hanoi, VN" ] cities.any { it.name.indexOf(" ") != -1 } == true cities.every { it.name.indexOf(" ") == -1 } == false cities.find { it.name.startsWith("H") }.name == "Hanoi"
  • 18.
  • 19. The End More on Groovy: Book: (I didn't write it!) Slides: Interactive: PDF: Thank you! Free: Groovy User Guide Groovy Recipes: Greasing the Wheels of Java Online compiler/runner http://slides.com/hroussel https://www.slideshare.net/hroussel Hervé Vũ Roussel http://herveroussel.com
  • 20. Groovify your Java CodeA guide to Groovy syntax for Java coders By Hervé Vũ Roussel for Agile Vietnam Coding Dojo 2014 Interactive slides at: https://slides.com/hroussel/groovify-your-java-code Groovify your Java code Edit deck title & description a day ago 0 68 Hervé Roussel http://www.herveroussel.com hvroussel 0 Tweet 0 0 Like We were unable to load Disqus. If you are a moderator please see our troubleshooting guide 0 Comments Slides Disqus Faceb Twitte Googl Login Newest Oldest Sort by Best Best Share Share this discussion on Start the discussion…