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
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"])
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
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…