Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - Overview



Groovy is an object oriented language which is based on Java platform. Groovy 1.0 was released in January 2, 2007 with Groovy 5.0.0 as the current major release. Groovy is distributed via the Apache License v 2.0.

What is Groovy

Groovy is a multi-faceted Java like language with added features. Groovy supports object oriented programming along with functional programming. Groovy exhibits both static as well as dynamic nature. Groovy provides strong envionment to create Domain Specific Languages. Groovy is fully interoperaable with Java and provide language extensions using in-language macros, AST transformations and meta programming capabilities.

  • JVM Based Language − Groovy compiles the code to java byte code and runs on JVM. Thus porting to Groovy is very easy as it uses the existing vast ecosystem of Java and its libraries.

  • Dynamic & Optional Typing − Where Java is strictly typed language, Groovy is a dynamically typed language by default which means we are not bound to declare variable types. Although static typing can be done to improve performance and utilize complie time checks.

  • Object Oriented & Scripting − Groovy is an object oriented language as well as a scripting language allowing to create full fledge application as well as quick scripts.

  • Syntactic Sugar − Groovy is an enhancement to Java providing more concise syntax and features streamlining programming practices.

Key Characteristics of Groovy

  • Conciseness − Groovy code is more concise and readable and reduces boilerplate code of java.

  • Closures − Groovy supports first class functions which can be passed as parameters to a function enabling functional programming language.

  • Metaprogramming − Groovy allows to modify class and objects at runtime using techniques like ExpandoMetaClass and categories.

  • DSL Support − Groovy's flexible syntax and support for Metaprogramming makes it an excellent choice for Domain Specific Language, DSL.

  • Native XML/JSON Processing − Groovy has inbuilt support for XML and JSON parsing and generation which is very useful in webservices interaction and data manipulations.

  • Java Interoperability − Groovy is bidirectionally compatible with Java. We can use Java libraries, java code, interfaces. Java code can call groovy code as well.

  • Safety Operators − Groovy provides elvis operator, ?: safe navigation operator, ?. to handle null values gracefully avoiding null pointer exceptions.

  • Simplified I/O − Groovy provides easy API to read/write files.

  • List and Map − Groovy provides a concise syntax to create lists and maps.

  • Operator Overloading − Groovy provides standard operators to be redefined for custom classes.

Advantages of Groovy

  • Increased Productivity − Groovy provides quicker developer with less code to write.

  • Reduced Boilerplate − Groovy reduces a lot of boilerplate code, simplifies patterns for data structures, I/O and concurrent programming.

  • Excellent Scripting Support − Groovy has excellent support for gradle scripts for testing, automating system administration tasks, rapid prototyping and lots more.

  • Easy Learning Curve − If you know java, learning Groovy is quite easy.

  • Community Support − Groovy has its own active community along with vast java communities.

Official Reference

The official website for Groovy is http://www.groovy-lang.org/

Groovy Official Website
Advertisements