Preface

Groovy 2 Cookbook consists of problem-solving recipes for Groovy, one of the most flexible programming languages we have ever used. Th book contains solutions to more than 100 common problems, shown with more than 500 Groovy code snippets.

There are a few unique things about this book:

  • As a cookbook, it's intended to save your time by providing solutions to the most common problems you'll encounter.
  • Most of the examples can be run as Groovy scripts or directly in the GroovyConsole. As a result, whether you're sitting by a computer or n a plane, you get the benefit of seeing their exact output.
  • The book covers not only the Groovy language, but also has several recipes on Groovy libraries and tools, including Gradle, concurrent programming and functional testing.

Th book covers Groovy 2.0 and 2.1.

The Groovy language

Groovy arises from the self-imposed limitations of the Java language. Java is an "old" language, originally conceived in 1990 and released at the beginning of 1996 (Java 1.0). We are looking at a 20 year life span that, in our field, is equivalent to an ice age. Java was portable (remember the motto "write once, run anywhere"?), sported a truly object-oriented core, and provided an automatic management of memory. The Java platform evolved in two directions: Java Virtual Machine, an outstanding piece of software engineering, which has become increasingly powerful and more performant over the years, and the actual Java language. The latter unquestionably matured and changed since its origin, but it did so in a unnerving slow-motion pace. The reason for this pondered evolution lies in the strong ties that the Java language historically had with the enterprise world. This bond acted as a double-edged weapon. It gave the language the massive adoption and popularity that it enjoys today, but it tampered the ability to quickly adapt to an ever-changing IT landscape.

In order to counteract the lethargic adoption of new features in Java, new languages based on the JVM started to see the light. Groovy is one of these languages, along with Scala, Clojure, JRuby, Jython and many others. So what is Groovy? Groovy is an optionally typed, dynamic language for the JVM with many features influenced by languages Python, Ruby, and Smalltalk, making them available to Java developers using a Java- syntax. Groovy is designed to work seamlessly with Java at every level, from syntax alignment to bytecode generation (although it creates different bytecode). The language evolved from being a limited scripting language to a fully-fledged programming language that can be used in very different contexts, such as web applications and services, backend servers, background jobs, desktop applications.

The dynamic nature of the language allows a degree of flexibility hardly achievable with Java. Thanks to the language's metaprogramming features, it is possible to modify or augment the code and behavior at runtime or even at compile time (using AST) and create Domain-Specific Languages (DSL) in a breeze. Furthermore Groovy adds a huge number of convenience methods and approaches that simplify your code and make it more powerful.

We, the authors, have been programming in Groovy for many years now. We hope that through this book, we will be able to convey the great fun and productivity boost that we enjoyed by using this language.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.43