Chapter 2. The Groovy essentials

 

This chapter covers

  • Introducing Groovy
  • Differences between Java and Groovy
  • Groovy’s dynamic features

Grails is a great framework that removes much of the drudgery from the development of web applications. You have already seen how easy it is to get a usable application up and running from scratch. A large part of that productivity gain comes from using Groovy as the main language for Grails development.

This chapter aims to be a primer for Java developers, covering basics that will be useful for following the rest of the book. The pace is fast, but you don’t have to understand everything in one go. In fact, we encourage you to refer back to this chapter as your experience grows and you need to dig a bit deeper into Groovy. If you’re already familiar with the language, you may still want to browse through the chapter—we talk about some subtleties and pitfalls that you may not be aware of.

We begin by covering the many small differences between Groovy and Java, most of which amount to simple variations in the syntax. We then highlight the Java features that are missing from Groovy (there are only a few), before moving on to closures and the dynamic nature of the language. Even after a quick read through, you’ll know enough to follow the examples in the book and write your own code. Beyond that, there is enough information in this chapter for you to become a competent Groovy (and Grails!) developer.

2.1. An introduction

2.2. Exploring types

2.3. Time-saving features

2.4. Expert Groovy

2.5. Summary and best practices

sitemap