Getting Started guide |
Groovy is a dynamically compiled object oriented language for the Java Virtual Machine (JVM).
Groovy features differentiating the language from Java 6 and earlier include:
- static and dynamic typing (with the def keyword),
- operator overloading
- lists and associative arrays (maps) native syntax
- regular expression native support
- polymorphic iteration
- string embedded expressions
- additional helper methods
- safe navigation operator "?." to automatically check for nulls (for example, "variable?.method()", or "variable?.field").
Groovy as a dynamic language
A Groovy script is fully parsed, compiled, and generated before execution. The process occurs under the hood, and the compiled version is not saved as an artifact of the process.
A map is used to store "associative arrays" or "dictionaries", an unordered collection of heterogeneous, named data.
For example, we want to store names and IQ scores:
Note that each of the values stored in the map is of a different type. Brett's is an integer, Pete's is a string, and Andrew's is a floating point number. We can access the values in a map in two main ways: