Let's get into groove with 'GROOVY'

Groovy is a feature-rich,java-friendly, optionally typed, dynamic language that runs on the JVM. Groovy source code is compiled into Java byte-code by the Groovy compile.It provides lots of simplifications compared to the Java programming language and advanced language features such as properties, closures, dynamic methods,  native support for lists, maps, regular expressions and duck typing.

println 'Hello World'
A Groovy source files ends with the .groovy extension.

Every Groovy type is a subclass of java.lang.Object.Groovy code can call Java code and Java code can call Groovy code. Every Groovy class is compiled into a Java class and you can use the new operator in Java to create instances of the Groovy class. This instance can be used to call methods or to pass as parameter to a fitting Java method. Groovy classes can extend Java classes and Java classes can also extend Groovy classes.

In the beginning I said that Groovy is simple and advanced.Let's see how.
 >Groovy does not require semicolons at the end of statements
 >In a method the last expression is returned, 'return' keyword not required.
 >Optional typing: The def keyword is used to indicate that no particular type is demanded

 >Parsing and creating XML, JSON and files is very simple with Groovy
 >Groovy automatically imports the following packages and classes which can be used in Groovy without specifying the package name.

    groovy.lang.*
    groovy.util.*
    java.lang.*
    java.util.*
    java.net.*
    java.io.*
    java.math.BigInteger
    java.math.BigDecimal
 > x=x+3 is equivalent to x=x.plus(3) operator overloading
 > There is a difference between Java and Groovy on handling dot (.) operator. Java uses the dot operator to access properties and groovy also support dot operator but unlike Java call actually go through getters and setters, which is automatically generated in groovy. For example

         Student st = new Student()
         st.StudentID = 400

     In groovy you can also use
         st.setStudentID(400)
will call mutator setStudentID(value) from the Student class.



 next topic groovy closure

Comments

Popular Posts