Groovy
Apache Groovy is a Java-syntax-compatible object-oriented-programming language which means the code is written using classes, methods and fields. It runs on Java platform, the source code is compiled to byte code and runs on Java Virtual Machines (JVM).
Followings are the few features of Groovy:
- It is compact and easy to learn syntax.
- It integrates with Java programs and libraries.
- Java code can be enhanced using Groovy and we can also mix them if needed.
- Groovy uses advanced programming concepts like Metaprogramming, Functional Programming and Closures.
Although Groovy syntax is quite different from from Java’s syntax but one can write Java code in Groovy file without any compilation error.
Example:

On running the command groovy HelloWorld, it will print the corresponding statements in output console without any error.
Groovy’s advanced programming concepts aids developer to unlock the capabilities and go beyond the limitations of Java.
Java vs Groovy:
- Java only allows static typing whereas Groovy allows both statically-typed and dynamic-typed (no need to declare the data-type of a variable instead use def keyword).
- Java requires developer to write boilerplate code such as Getter and Setter methods for the class member(s) whereas Groovy generates both methods at runtime so no need to write it.
- In Java, developer needs to explicitly define constructor(s), equals, hashCode and toString methods whereas Groovy provides annotations such as @EqualsHashCode for generating these methods at compile time. It is also called AST Transformation.
- In Java by default java.lang.* package is imported whereas Groovy automatically imports commonly used packages such as java.util.* and java.io.*.
- In Java, the default modifier is package-private i.e. default whereas in Groovy the default modifier is public. We can enforce encapsulation based on need.
- In Java, semicolon is needed to separate two statements but in Groovy it is optional.
I have included but not limited features of Groovy and also compared it with Java. Hope this article helped you to understand the capabilities of Groovy over Java.
Thanks and happy learning.