Programming Groovy 2

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 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.

Table of contents

  1. Programming Groovy 2
  2. For the Best Reading Experience...
  3. Table of Contents
  4. What readers are saying about Programming Groovy 2
  5. Foreword to the Second Edition
  6. Introduction
    1. What’s Groovy?
    2. Why Dynamic Languages?
    3. Why Groovy?
    4. What’s in This Book?
    5. Changes Since This Book’s First Edition
    6. Who Is This Book For?
    7. Online Resources
    8. Acknowledgments
  7. Part 1: Beginning Groovy
  8. Chapter 1: Getting Started
    1. Installing Groovy
    2. Installing and Managing Groovy Versions
    3. Test-Drive Using groovysh
    4. Using groovyConsole
    5. Running Groovy on the Command Line
    6. Using an IDE
  9. Chapter 2: Groovy for Java Eyes
    1. From Java to Groovy
    2. JavaBeans
    3. Flexible Initialization and Named Arguments
    4. Optional Parameters
    5. Using Multiple Assignments
    6. Implementing Interfaces
    7. Groovy Boolean Evaluation
    8. Operator Overloading
    9. Support of Java 5 Language Features
    10. Using Groovy Code-Generation Transformations
    11. Gotchas
  10. Chapter 3: Dynamic Typing
    1. Typing in Java
    2. Dynamic Typing
    3. Dynamic Typing != Weak Typing
    4. Design by Capability
    5. Optional Typing
    6. Multimethods
    7. Dynamic: To Be or Not to Be?
    8. Switching Off Dynamic Typing
  11. Chapter 4: Using Closures
    1. The Convenience of Closures
    2. Programming with Closures
    3. Ways to Use Closures
    4. Passing Parameters to Closures
    5. Using Closures for Resource Cleanup
    6. Closures and Coroutines
    7. Curried Closure
    8. Dynamic Closures
    9. Closure Delegation
    10. Programming with Tail Recursion
    11. Improving Performance Using Memoization
  12. Chapter 5: Working with Strings
    1. Literals and Expressions
    2. GString Lazy-Evaluation Problem
    3. Multiline Strings
    4. String Convenience Methods
    5. Regular Expressions
  13. Chapter 6: Working with Collections
    1. Using List
    2. Iterating Over an ArrayList
    3. Using Finder Methods
    4. Other Convenience Methods on List s
    5. Using the Map Class
    6. Iterating Over Map
    7. Other Convenience Methods on Map s
  14. Part 2: Using Groovy
  15. Chapter 7: Exploring the GDK
    1. Using Object Extensions
    2. Other Extensions
    3. Custom Methods Using the Extension Modules
  16. Chapter 8: Working with XML
    1. Parsing XML
    2. Creating XML
  17. Chapter 9: Working with Databases
    1. Setting Up the Database
    2. Connecting to a Database
    3. Database Select
    4. Transforming Data to XML
    5. Using DataSet
    6. Inserting and Updating
    7. Accessing Microsoft Excel
  18. Chapter 10: Working with Scripts and Classes
    1. The Melting Pot of Java and Groovy
    2. Running Groovy
    3. Using Groovy Classes from Groovy
    4. Intermixing Groovy and Java with Joint Compilation
    5. Creating and Passing Groovy Closures from Java
    6. Calling Groovy Dynamic Methods from Java
    7. Using Java Classes from Groovy
    8. Using Groovy Scripts from Groovy
    9. Using Groovy Scripts from Java
  19. Part 3: MOPping Groovy
  20. Chapter 11: Exploring Metaobject Protocol (MOP)
    1. Groovy Object
    2. Querying Methods and Properties
    3. Dynamically Accessing Objects
  21. Chapter 12: Intercepting Methods Using MOP
    1. Intercepting Methods Using GroovyInterceptable
    2. Intercepting Methods Using MetaClass
  22. Chapter 13: MOP Method Injection
    1. Injecting Methods Using Categories
    2. Injecting Methods Using ExpandoMetaClass
    3. Injecting Methods into Specific Instances
    4. Injecting Methods Using Mixins
    5. Decorating Classes with Multiple Mixins
  23. Chapter 14: MOP Method Synthesis
    1. Method Synthesis Using methodMissing
    2. Method Synthesis Using ExpandoMetaClass
    3. Synthesizing Methods for Specific Instances
  24. Chapter 15: MOPping Up
    1. Creating Dynamic Classes with Expando
    2. Method Delegation: Putting It All Together
    3. Review of MOP Techniques
  25. Chapter 16: Applying Compile-Time Metaprogramming
    1. Analyzing Code at Compile Time
    2. Intercepting Method Calls Using AST Transformations
    3. Injecting Methods Using AST Transformations
  26. Part 4: Using Metaprogramming
  27. Chapter 17: Groovy Builders
    1. Building XML
    2. Building JSON
    3. Building Swing
    4. Custom Builder Using Metaprogramming
    5. Using BuilderSupport
    6. Using FactoryBuilderSupport
  28. Chapter 18: Unit Testing and Mocking
    1. Code in This Book and Automated Unit Tests
    2. Unit Testing Java and Groovy Code
    3. Testing for Exceptions
    4. Mocking
    5. Mocking by Overriding
    6. Mocking Using Categories
    7. Mocking Using ExpandoMetaClass
    8. Mocking Using Expando
    9. Mocking Using Map
    10. Mocking Using the Groovy Mock Library
  29. Chapter 19: Creating DSLs in Groovy
    1. Context
    2. Fluency
    3. Types of DSLs
    4. Designing Internal DSLs
    5. Groovy and DSLs
    6. Using Command-Chain Fluency
    7. Closures and DSLs
    8. Method Interception and DSLs
    9. The Parentheses Limitation and a Workaround
    10. Categories and DSLs
    11. ExpandoMetaClass and DSLs
  30. Appendix 1: Web Resources
  31. Appendix 2: Bibliography
    1. You May Be Interested In…

Product information

  • Title: Programming Groovy 2
  • Author(s):
  • Release date: July 2013
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781937785307