Thursday, January 23, 2014

Groovy Tutorial 1: Why Learn Groovy?

Groovy Tutorial 1: Why Learn Groovy?
For most people who are not java developers, Java is a language, the one used to write Android apps. However, not only is Java a great language for Enterprise apps as well as small computing devices such as card and FFID readers as well as smart cards, it is a whole ecosystem compromising the language, the libraries as well as the JVM.
The Java Virtual Machine is a powerful tool that any programmer can harness, and can technically run on a computer with no OS, which is what allows it to run on SIM cards and other computing platforms that run firmware or with rudimentary OSes.
Several languages can run on the JVM, including Groovy, Scala, JRuby, JPython and many more. They allows for easy integration with Java, harnessing the benefits of Java’s JVM while maintaining the syntax of the respective languages they are derived from.  
For Java Developers however, Groovy is the language to go with. Any Java code is Groovy code, and while most of the other languages running on the JVM can make the same claim, Groovy is designed to maintain Java’s syntax. It offers features that are only coming to Java such as closures and many more, more succinct and beautiful code…
We will get to more reasons for why you should learn Groovy, but here they are in passing:
Succinct
Extends the JDK.
Meta programming!!!!
Flat learning curve.
Fully Dynamic.
It is fun and awesome and cool and, am losing the plot here….
Here are a few code samples to demonstrate Groovy’s succinctness:
HelloWorld.groovy
println 'Hello World'
Output
Hello Word



HelloYou.groovy
def name='My name'
println "Hello $name"
Output
Hello My name

PrintNames.groovy
def printName={it -> print "$it " }
def names=["Groovy","is",'simply','Awesome']
names.each(printName)  //the braces are optional i.e. names.map printName
Output
Groovy is simply Awesome
Happy coding with Cabee Grovy Mastery Course!!!

2 comments: