Groovy Introduction

Apache Groovy is a powerful Dynamic, objected oriented, scripting language for JVM , optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax.

Seamless integration with Java > Designed with Java in mind from the beginning (unlike other scripting languages) It integrates smoothly with any Java program, and immediately delivers to your application powerful features, including scripting capabilities, Domain-Specific Language authoring, runtime and compile-time meta-programming and functional programming.

Features of Groovy

Features Description
Dynamic Groovy is a dynamic language “specifically” designed for Java platform,Groovy code, when compiled, generated Java bytecode
Powerful Groovy code, when compiled, generated Java bytecode , Leverage the benefit of JVM ,Existing Java code works in Groovy environment “as it is” basis > Incremental change is possible, in fact, recommended (when you plan to migrate existing Java code to Groovy)
Scripting Language
  • Closure (Java 8 now supports closure through Lambda)
  • Meta-programming • Provides easier development environment
  • Scripting > Combines compilation and execution into a single step
  • Shell interpreter
Domain specific  
Compile time Meta Programming  
Static typing  
Static compile Time Typing  
scripting Language for JVM
  • JVM is proven to be a great run-time platform, however
  • Secure, highly performing, mature, etc
  • There are large number “ready to use” Java libraries over JVM
  • Commercial and open-sourced
  • So we need a better programming language leveraging the current JVM
  • More productive, more fun, less verbose syntax
  • With modern language features
  • Seamless interoperability with Java programs
  • Viable Choices > Groovy, Scala, JRuby, Clojure
Compile Time Meta Programming
Easy Syntax to learn
  • “def" is a replacement for a type in variable definitions
  • “def” is used to indicate that you don't care about the type
  • You can also think of "def" as an alias of "Object"
    • def dynamic = 1 println dynamic
      // 1 println dynamic.class // java.lang.Integer
      dynamic = "I am a String stored in a variable of dynamic type"
      println dynamic // I am a String stored in a variable of dynamic type
      println dynamic.class // java.lang.Strin