SlideShare a Scribd company logo
Productive (Web)
Programming with Groovy
S G Ganesh
Independent Consultant,Trainer, and Author
sgganesh@gmail.com
Introducing Groovy
Groovy enters the top 20
of TIOBE index!
1.7 million
downloads in
2012!
How I felt Programming in
Groovy vs. Java
“Hello World” Example
class Hello {
! public static void main(String []args) {
! ! System.out.println("hello world");
! }
}
class Hello {
! public static void main(String []args) {
! ! System.out.println("hello world");
! }
}
First (simple) Example
import java.io.*;
class Type {

 public static void main(String []files) {

 
 // process each file passed as argument

 
 for(String file : files) {

 
 
 // try opening the file with FileReader

 
 
 try (FileReader inputFile = new FileReader(file)) {

 
 
 
 int ch = 0;

 
 
 
 while( (ch = inputFile.read()) != -1) {

 
 
 
 
 // ch is of type int - convert it back to char

 
 
 
 
 System.out.print( (char)ch );

 
 
 
 }

 
 
 } catch (FileNotFoundException fnfe) {

 
 
 
 System.err.printf("Cannot open the given file %s ", file);

 
 
 }

 
 
 catch(IOException ioe) {

 
 
 
 System.err.printf("Error when processing file %s; skipping it", file);

 
 
 }

 
 
 // try-with-resources will automatically release FileReader object

 
 }

 }
}
args.each { println new File(it).getText() }
Mere “Syntactic Sugar?”
Map<String, String> inglishWords = new HashMap<>();
inglishWords.put("Shampoo", "'Chapmo' (Hindi)");
inglishWords.put("Sugar", "'Sarkkarai' (Tamil)");
inglishWords.put("Copra", "'Koppara' (Malayalam)");
inglishWords.put("Jute", "'Jhuto' (Bengali)");
inglishWords.put("Cot", "'Khatva' (Sanskrit)");
for(Map.Entry<String, String> word : inglishWords.entrySet()) {
System.out.printf("%s => %s n", word.getKey(), word.getValue());
}
def inglishWords = [ "Shampoo" : "'Chapmo' (Hindi)",
"Sugar" : "'Sarkkarai' (Tamil)",
"Copra" : "'Koppara' (Malayalam)",
"Jute" : "'Jhuto' (Bengali)",
"Cot" : "'Khatva' (Sanskrit)" ]
inglishWords.each {
key, value ->
println "$key => $value"
}
Just “Concise”
Expression?
System.out.println("The (key-based) sorted map is: ");
Map<String, String> keySortedMap = new TreeMap<>(inglishWords);
for(Map.Entry<String, String> word : keySortedMap.entrySet()) {
System.out.printf("%s => %s n", word.getKey(), word.getValue());
}
println "The (key-based) sorted map is: "
def keySortedMap = inglishWords.sort()
keySortedMap.each {
key, value ->
println "$key => $value"
}
11
Now for the real magic
with Groovy :-)class MapUtil {
// this code segment from http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map ) {
List<Map.Entry<K, V>> list =
new LinkedList<Map.Entry<K, V>>( map.entrySet() );
Collections.sort( list, new Comparator<Map.Entry<K, V>>() {
public int compare( Map.Entry<K, V> o1, Map.Entry<K, V> o2 )
{
return (o1.getValue()).compareTo( o2.getValue() );
}
} );
Map<K, V> result = new LinkedHashMap<K, V>();
for (Map.Entry<K, V> entry : list) {
result.put( entry.getKey(), entry.getValue() );
}
return result;
}
}
System.out.println("The (value-based) sorted map is: ");

Map<String, String> valueSortedMap = MapUtil.sortByValue(inglishWords);


for(Map.Entry<String, String> word : valueSortedMap.entrySet()) {
System.out.printf("%s => %s n", word.getKey(), word.getValue());
}
println "The (value-based) sorted map is: "
def valueSortedMap = inglishWords.sort
{ it.value }
valueSortedMap.each {
key, value ->
println "$key => $value"
}
HTML Creation
Example
try (PrintWriter pw = new PrintWriter(new FileWriter("./index.java.html"))) {

 pw.println("<html> <head> <title>Words from Indian origin in English</title> </head>
<body>");

 pw.println("<h1>Words from Indian origin in English</h1>");

 pw.println("<table border='1'> <tr> <th>Inglish word</th> <th>Origin</th></tr>");

 for(Map.Entry<String, String> word : inglishWords.entrySet()) {


 pw.printf("<tr> <td> %s </td> <td> %s </td> </tr>", word.getKey(),
word.getValue());
}

 pw.println("</table> <p style='font-style:italic;font-size:small;float:right'>Results obtained at "
+ new Date() + "</p> </body> </html>"); 
}
HTML Creation
Exampledef writer = new StringWriter()
def doc = new MarkupBuilder(writer)
doc.html() {
head {
title("Words from Indian origin in English")
}
body {
h1("Words from Indian origin in English")
table(border:1) {
tr {
th("Inglish word")
th("Origin")
}
inglishWords.each { word, root ->
tr {
td("$word")
td("$root")
}
}
}
p(style:'font-style:italic;font-size:small;float:right', "Results obtained at ${new
Date().dateTimeString}")
}
}
Not Convinced? Check
XML Creation Example
try (PrintWriter pw = new PrintWriter(new FileWriter("./words.xml"))) {

 pw.println("<inglishwords>");

 for(Map.Entry<String, String> word : inglishWords.entrySet()) {

pw.printf("t<language word='%s'> n tt <origin>

 
 '%s'</origin> n t </language> n", word.getKey(), word.getValue());
}

 pw.println("</inglishwords>");
}
xmlbuilder = new groovy.xml.MarkupBuilder()
xmlbuilder.inglishwords {
words.each { key, value ->
language(word:key) { origin(value) }
}
}
Where to Learn More
About Groovy?
http://groovy.codehaus.org
sgganesh@gmail.com
http://ocpjp7.blogspot.in

More Related Content

What's hot

Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python Script
Survey Department
 
Q
QQ
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Tsuyoshi Yamamoto
 
Green dao
Green daoGreen dao
Green dao
彥彬 洪
 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDB
Sqreen
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
Peter Eisentraut
 
ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android
哲偉 楊
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
Booch Lin
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
Paul King
 
Template Haskell とか
Template Haskell とかTemplate Haskell とか
Template Haskell とか
Hiromi Ishii
 
greenDAO
greenDAOgreenDAO
greenDAO
Mu Chun Wang
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014
Henning Jacobs
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
Jason Terpko
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
Websecurify
 
Power shell
Power shellPower shell
Power shell
LearningTech
 
Terraform for fun and profit
Terraform for fun and profitTerraform for fun and profit
Terraform for fun and profit
Bram Vogelaar
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
Alberto Paro
 
B03-GenomeContent-Intermine
B03-GenomeContent-IntermineB03-GenomeContent-Intermine
B03-GenomeContent-Intermine
Bioinformatics Open Source Conference
 

What's hot (19)

Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python Script
 
Q
QQ
Q
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
Green dao
Green daoGreen dao
Green dao
 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDB
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
 
Template Haskell とか
Template Haskell とかTemplate Haskell とか
Template Haskell とか
 
greenDAO
greenDAOgreenDAO
greenDAO
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
Power shell
Power shellPower shell
Power shell
 
Terraform for fun and profit
Terraform for fun and profitTerraform for fun and profit
Terraform for fun and profit
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
 
B03-GenomeContent-Intermine
B03-GenomeContent-IntermineB03-GenomeContent-Intermine
B03-GenomeContent-Intermine
 

Viewers also liked

Amar
AmarAmar
Il ruolo del Web nella promozione della struttura turistica
Il ruolo del Web nella promozione della struttura turisticaIl ruolo del Web nella promozione della struttura turistica
Il ruolo del Web nella promozione della struttura turistica
Claudia Zarabara
 
FPT IS
FPT ISFPT IS
Storia antica Grecia e Roma slideshare
Storia antica Grecia e Roma slideshareStoria antica Grecia e Roma slideshare
Storia antica Grecia e Roma slideshare
Vito Dioguardi
 
Innovatiecafé: Learning analytics
Innovatiecafé: Learning analyticsInnovatiecafé: Learning analytics
Innovatiecafé: Learning analytics
SURF Events
 
Come lanciare un podcast e guadagnarsi visibilità immediata, quando tutti lot...
Come lanciare un podcast e guadagnarsi visibilità immediata, quando tutti lot...Come lanciare un podcast e guadagnarsi visibilità immediata, quando tutti lot...
Come lanciare un podcast e guadagnarsi visibilità immediata, quando tutti lot...
Marketing Semplice
 
2015-12 Nederlands leren als volwassene
2015-12 Nederlands leren als volwassene2015-12 Nederlands leren als volwassene
2015-12 Nederlands leren als volwassene
SAAMO Antwerpen vzw
 
La prima certificazione per i dsa - Elena Berselli
La prima certificazione per i dsa - Elena BerselliLa prima certificazione per i dsa - Elena Berselli
La prima certificazione per i dsa - Elena Berselli
Ordine Psicologi della Lombardia
 
Leren lesgeven met ict de lerarenopleider als rolmodel
Leren lesgeven met ict de lerarenopleider als rolmodelLeren lesgeven met ict de lerarenopleider als rolmodel
Leren lesgeven met ict de lerarenopleider als rolmodel
SURF Events
 
Onderwijs op maat? Dat kan bij ons niet!
Onderwijs op maat? Dat kan bij ons niet!Onderwijs op maat? Dat kan bij ons niet!
Onderwijs op maat? Dat kan bij ons niet!
SURF Events
 
Causes Of Deforestation
Causes Of DeforestationCauses Of Deforestation
Causes Of Deforestation
Coral
 
Vana-Egiptus
Vana-EgiptusVana-Egiptus
Vana-Egiptus
Natalja Dovgan
 
Poliitilised õpetused
Poliitilised õpetusedPoliitilised õpetused
Poliitilised õpetused
Natalja Dovgan
 
Kaubandus ja tööstus
Kaubandus ja tööstusKaubandus ja tööstus
Kaubandus ja tööstus
Natalja Dovgan
 
Balti erikord ja asehalduskord
Balti erikord ja asehalduskordBalti erikord ja asehalduskord
Balti erikord ja asehalduskord
Natalja Dovgan
 

Viewers also liked (16)

Amar
AmarAmar
Amar
 
Il ruolo del Web nella promozione della struttura turistica
Il ruolo del Web nella promozione della struttura turisticaIl ruolo del Web nella promozione della struttura turistica
Il ruolo del Web nella promozione della struttura turistica
 
FPT IS
FPT ISFPT IS
FPT IS
 
Storia antica Grecia e Roma slideshare
Storia antica Grecia e Roma slideshareStoria antica Grecia e Roma slideshare
Storia antica Grecia e Roma slideshare
 
Innovatiecafé: Learning analytics
Innovatiecafé: Learning analyticsInnovatiecafé: Learning analytics
Innovatiecafé: Learning analytics
 
Come lanciare un podcast e guadagnarsi visibilità immediata, quando tutti lot...
Come lanciare un podcast e guadagnarsi visibilità immediata, quando tutti lot...Come lanciare un podcast e guadagnarsi visibilità immediata, quando tutti lot...
Come lanciare un podcast e guadagnarsi visibilità immediata, quando tutti lot...
 
2015-12 Nederlands leren als volwassene
2015-12 Nederlands leren als volwassene2015-12 Nederlands leren als volwassene
2015-12 Nederlands leren als volwassene
 
La prima certificazione per i dsa - Elena Berselli
La prima certificazione per i dsa - Elena BerselliLa prima certificazione per i dsa - Elena Berselli
La prima certificazione per i dsa - Elena Berselli
 
Leren lesgeven met ict de lerarenopleider als rolmodel
Leren lesgeven met ict de lerarenopleider als rolmodelLeren lesgeven met ict de lerarenopleider als rolmodel
Leren lesgeven met ict de lerarenopleider als rolmodel
 
Onderwijs op maat? Dat kan bij ons niet!
Onderwijs op maat? Dat kan bij ons niet!Onderwijs op maat? Dat kan bij ons niet!
Onderwijs op maat? Dat kan bij ons niet!
 
Causes Of Deforestation
Causes Of DeforestationCauses Of Deforestation
Causes Of Deforestation
 
Vana-Egiptus
Vana-EgiptusVana-Egiptus
Vana-Egiptus
 
Poliitilised õpetused
Poliitilised õpetusedPoliitilised õpetused
Poliitilised õpetused
 
Kaubandus ja tööstus
Kaubandus ja tööstusKaubandus ja tööstus
Kaubandus ja tööstus
 
Balti erikord ja asehalduskord
Balti erikord ja asehalduskordBalti erikord ja asehalduskord
Balti erikord ja asehalduskord
 
Kuldvillak 7 kl
Kuldvillak 7 klKuldvillak 7 kl
Kuldvillak 7 kl
 

Similar to Productive Programming in Groovy

Cascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUGCascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUG
Matthew McCullough
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
Hugo Gävert
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Vitaly Gordon
 
Jakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheelJakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheel
tcurdt
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
Kiyotaka Oku
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
Kazuchika Sekiya
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
Ganesh Samarthyam
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
Vaclav Pech
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecture
zefhemel
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
Codecamp Romania
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
Sandeep Kr. Singh
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
Scott Leberknight
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code Examples
Naresh Chintalcheru
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using Scalding
Toni Cebrián
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QAFest
 

Similar to Productive Programming in Groovy (20)

Cascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUGCascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUG
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
Jakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheelJakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheel
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecture
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code Examples
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using Scalding
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
 

More from Ganesh Samarthyam

Wonders of the Sea
Wonders of the SeaWonders of the Sea
Wonders of the Sea
Ganesh Samarthyam
 
Animals - for kids
Animals - for kids Animals - for kids
Animals - for kids
Ganesh Samarthyam
 
Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in Practice
Ganesh Samarthyam
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”
Ganesh Samarthyam
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't Enough
Ganesh Samarthyam
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
Ganesh Samarthyam
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief Presentation
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - Poster
Ganesh Samarthyam
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)
Ganesh Samarthyam
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship Deck
Ganesh Samarthyam
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
Ganesh Samarthyam
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
Ganesh Samarthyam
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz Questions
Ganesh Samarthyam
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
Ganesh Samarthyam
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
Ganesh Samarthyam
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
Ganesh Samarthyam
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quiz
Ganesh Samarthyam
 

More from Ganesh Samarthyam (20)

Wonders of the Sea
Wonders of the SeaWonders of the Sea
Wonders of the Sea
 
Animals - for kids
Animals - for kids Animals - for kids
Animals - for kids
 
Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in Practice
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't Enough
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief Presentation
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - Poster
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship Deck
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz Questions
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quiz
 

Recently uploaded

OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 

Recently uploaded (20)

OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 

Productive Programming in Groovy

  • 1. Productive (Web) Programming with Groovy S G Ganesh Independent Consultant,Trainer, and Author sgganesh@gmail.com
  • 3. Groovy enters the top 20 of TIOBE index! 1.7 million downloads in 2012!
  • 4. How I felt Programming in Groovy vs. Java
  • 5. “Hello World” Example class Hello { ! public static void main(String []args) { ! ! System.out.println("hello world"); ! } } class Hello { ! public static void main(String []args) { ! ! System.out.println("hello world"); ! } }
  • 6. First (simple) Example import java.io.*; class Type { public static void main(String []files) { // process each file passed as argument for(String file : files) { // try opening the file with FileReader try (FileReader inputFile = new FileReader(file)) { int ch = 0; while( (ch = inputFile.read()) != -1) { // ch is of type int - convert it back to char System.out.print( (char)ch ); } } catch (FileNotFoundException fnfe) { System.err.printf("Cannot open the given file %s ", file); } catch(IOException ioe) { System.err.printf("Error when processing file %s; skipping it", file); } // try-with-resources will automatically release FileReader object } } } args.each { println new File(it).getText() }
  • 7.
  • 8. Mere “Syntactic Sugar?” Map<String, String> inglishWords = new HashMap<>(); inglishWords.put("Shampoo", "'Chapmo' (Hindi)"); inglishWords.put("Sugar", "'Sarkkarai' (Tamil)"); inglishWords.put("Copra", "'Koppara' (Malayalam)"); inglishWords.put("Jute", "'Jhuto' (Bengali)"); inglishWords.put("Cot", "'Khatva' (Sanskrit)"); for(Map.Entry<String, String> word : inglishWords.entrySet()) { System.out.printf("%s => %s n", word.getKey(), word.getValue()); } def inglishWords = [ "Shampoo" : "'Chapmo' (Hindi)", "Sugar" : "'Sarkkarai' (Tamil)", "Copra" : "'Koppara' (Malayalam)", "Jute" : "'Jhuto' (Bengali)", "Cot" : "'Khatva' (Sanskrit)" ] inglishWords.each { key, value -> println "$key => $value" }
  • 9. Just “Concise” Expression? System.out.println("The (key-based) sorted map is: "); Map<String, String> keySortedMap = new TreeMap<>(inglishWords); for(Map.Entry<String, String> word : keySortedMap.entrySet()) { System.out.printf("%s => %s n", word.getKey(), word.getValue()); } println "The (key-based) sorted map is: " def keySortedMap = inglishWords.sort() keySortedMap.each { key, value -> println "$key => $value" }
  • 10.
  • 11. 11
  • 12. Now for the real magic with Groovy :-)class MapUtil { // this code segment from http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map ) { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>( map.entrySet() ); Collections.sort( list, new Comparator<Map.Entry<K, V>>() { public int compare( Map.Entry<K, V> o1, Map.Entry<K, V> o2 ) { return (o1.getValue()).compareTo( o2.getValue() ); } } ); Map<K, V> result = new LinkedHashMap<K, V>(); for (Map.Entry<K, V> entry : list) { result.put( entry.getKey(), entry.getValue() ); } return result; } } System.out.println("The (value-based) sorted map is: "); Map<String, String> valueSortedMap = MapUtil.sortByValue(inglishWords); for(Map.Entry<String, String> word : valueSortedMap.entrySet()) { System.out.printf("%s => %s n", word.getKey(), word.getValue()); } println "The (value-based) sorted map is: " def valueSortedMap = inglishWords.sort { it.value } valueSortedMap.each { key, value -> println "$key => $value" }
  • 13.
  • 14.
  • 15. HTML Creation Example try (PrintWriter pw = new PrintWriter(new FileWriter("./index.java.html"))) { pw.println("<html> <head> <title>Words from Indian origin in English</title> </head> <body>"); pw.println("<h1>Words from Indian origin in English</h1>"); pw.println("<table border='1'> <tr> <th>Inglish word</th> <th>Origin</th></tr>"); for(Map.Entry<String, String> word : inglishWords.entrySet()) { pw.printf("<tr> <td> %s </td> <td> %s </td> </tr>", word.getKey(), word.getValue()); } pw.println("</table> <p style='font-style:italic;font-size:small;float:right'>Results obtained at " + new Date() + "</p> </body> </html>"); }
  • 16. HTML Creation Exampledef writer = new StringWriter() def doc = new MarkupBuilder(writer) doc.html() { head { title("Words from Indian origin in English") } body { h1("Words from Indian origin in English") table(border:1) { tr { th("Inglish word") th("Origin") } inglishWords.each { word, root -> tr { td("$word") td("$root") } } } p(style:'font-style:italic;font-size:small;float:right', "Results obtained at ${new Date().dateTimeString}") } }
  • 17. Not Convinced? Check XML Creation Example try (PrintWriter pw = new PrintWriter(new FileWriter("./words.xml"))) { pw.println("<inglishwords>"); for(Map.Entry<String, String> word : inglishWords.entrySet()) { pw.printf("t<language word='%s'> n tt <origin> '%s'</origin> n t </language> n", word.getKey(), word.getValue()); } pw.println("</inglishwords>"); } xmlbuilder = new groovy.xml.MarkupBuilder() xmlbuilder.inglishwords { words.each { key, value -> language(word:key) { origin(value) } } }
  • 18.
  • 19. Where to Learn More About Groovy?