Book description
Groovy brings you the best of both worlds: a flexible, highly productive, agile, dynamic language that runs on the rich framework of the Java Platform. Groovy preserves the Java semantics and extends the JDK to give you true dynamic language capabilities. Programming Groovy 2 will help you, the experienced Java developer, learn and take advantage of the latest version of this rich dynamic language. You'll go from the basics of Groovy to the latest advances in the language, including options for type checking, tail-call and memoization optimizations, compile time metaprogramming, and fluent interfaces to create DSLs.
You don't have to leave the rich Java Platform to take advantage of Groovy. Groovy preserves Java's semantics and extends the JDK, so programming in Groovy feels like the Java language has been augmented; it's like working with a lighter, more elegant Java. If you're an experienced Java developer who wants to learn how Groovy works, you'll find exactly what you need in this book.
You'll start with the fundamentals of programming in Groovy and how it works with Java, and then you'll explore advanced concepts such as unit testing with mock objects, using Builders, working with databases and XML, and creating DSLs. You'll master Groovy's powerful yet complex run-time and compile-time metaprogramming features.
Much has evolved in the Groovy language since the publication of the first edition of Programming Groovy. Programming Groovy 2 will help you learn and apply Groovy's new features. Creating DSLs is easier now, and Groovy's already-powerful metaprogramming facilities have improved even more. You'll see how to work with closures, including tail call optimization and memoization. The book also covers Groovy's new static compilation feature.
Whether you're learning the basics of the language or interested in getting proficient with the new features, Programming Groovy 2 has you covered.
What You Need
To work on the examples in the book you need Groovy 2.0.5 and Java JDK 5 or higher.
Table of contents
- Programming Groovy 2
-
- Table of Contents
- What readers are saying about Programming Groovy 2
- Foreword to the Second Edition
- Introduction
- Part 1: Beginning Groovy
- Chapter 1: Getting Started
-
Chapter 2: Groovy for Java Eyes
- 2.1 From Java to Groovy
- 2.2 JavaBeans
- 2.3 Flexible Initialization and Named Arguments
- 2.4 Optional Parameters
- 2.5 Using Multiple Assignments
- 2.6 Implementing Interfaces
- 2.7 Groovy Boolean Evaluation
- 2.8 Operator Overloading
- 2.9 Support of Java 5 Language Features
- 2.10 Using Groovy Code-Generation Transformations
- 2.11 Gotchas
- Chapter 3: Dynamic Typing
-
Chapter 4: Using Closures
- 4.1 The Convenience of Closures
- 4.2 Programming with Closures
- 4.3 Ways to Use Closures
- 4.4 Passing Parameters to Closures
- 4.5 Using Closures for Resource Cleanup
- 4.6 Closures and Coroutines
- 4.7 Curried Closure
- 4.8 Dynamic Closures
- 4.9 Closure Delegation
- 4.10 Programming with Tail Recursion
- 4.11 Improving Performance Using Memoization
- Chapter 5: Working with Strings
- Chapter 6: Working with Collections
- Part 2: Using Groovy
- Chapter 7: Exploring the GDK
- Chapter 8: Working with XML
- Chapter 9: Working with Databases
-
Chapter 10: Working with Scripts and Classes
- 10.1 The Melting Pot of Java and Groovy
- 10.2 Running Groovy
- 10.3 Using Groovy Classes from Groovy
- 10.4 Intermixing Groovy and Java with Joint Compilation
- 10.5 Creating and Passing Groovy Closures from Java
- 10.6 Calling Groovy Dynamic Methods from Java
- 10.7 Using Java Classes from Groovy
- 10.8 Using Groovy Scripts from Groovy
- 10.9 Using Groovy Scripts from Java
- Part 3: MOPping Groovy
- Chapter 11: Exploring Metaobject Protocol (MOP)
- Chapter 12: Intercepting Methods Using MOP
- Chapter 13: MOP Method Injection
- Chapter 14: MOP Method Synthesis
- Chapter 15: MOPping Up
- Chapter 16: Applying Compile-Time Metaprogramming
- Part 4: Using Metaprogramming
- Chapter 17: Groovy Builders
-
Chapter 18: Unit Testing and Mocking
- 18.1 Code in This Book and Automated Unit Tests
- 18.2 Unit Testing Java and Groovy Code
- 18.3 Testing for Exceptions
- 18.4 Mocking
- 18.5 Mocking by Overriding
- 18.6 Mocking Using Categories
- 18.7 Mocking Using ExpandoMetaClass
- 18.8 Mocking Using Expando
- 18.9 Mocking Using Map
- 18.10 Mocking Using the Groovy Mock Library
- Chapter 19: Creating DSLs in Groovy
- Appendix 1: Web Resources
- Appendix 2: Bibliography
Product information
- Title: Programming Groovy 2
- Author(s):
- Release date: July 2013
- Publisher(s): Pragmatic Bookshelf
- ISBN: 9781680504347
You might also like
book
Making Java Groovy
Making Java Groovy is a practical handbook for developers who want to blend Groovy into their …
video
Up and Running Groovy
The goal of this screencast is to introduce the Groovy programming language to developers. Groovy is …
book
Groovy for Domain-specific Languages - Second Edition
Extend and enhance your Java applications with domain-specific scripting in Groovy About This Book Build domain-specific …
book
Introduction to JVM Languages
Explore the Java Virtual Machine with modern programming languages About This Book This guide provides in-depth …