Groovy Programming - 1st Edition - ISBN: 9780123725073, 9780080471594

Groovy Programming

1st Edition

An Introduction for Java Developers

Authors: Kenneth Barclay John Savage
Paperback ISBN: 9780123725073
eBook ISBN: 9780080471594
Imprint: Morgan Kaufmann
Published Date: 6th December 2006
Page Count: 496
Tax/VAT will be calculated at check-out
Compatible Not compatible
VitalSource PC, Mac, iPhone & iPad Amazon Kindle eReader
ePub & PDF Apple & PC desktop. Mobile devices (Apple & Android) Amazon Kindle eReader
Mobi Amazon Kindle eReader Anything else

Institutional Access


Groovy Programming is an introduction to the Java-based scripting language Groovy. Groovy has much in common with popular scripting languages such as Perl, Python, and Ruby, but is written in a Java-like syntax. And, unlike these other languages, Groovy is sanctioned by the Java community for use on the Java platform. Since it is based on Java, applications written in Groovy can make full use of the Java Application Programmer Interfaces (APIs). This means Groovy can integrate seamlessly with applications written in Java, while avoiding the complexities of the full Java language. This bare-bones structure also means Groovy can be used as an introduction to Java and to programming in general. Its simpler constructions and modern origins make it ideal as a first language and for introducing principles such as object-oriented programming.
This book introduces all the major aspects of Groovy development and emphasizes Groovy's potential as a learning tool. Case studies and exercises are included, along with numerous programming examples. The book begins assuming only a general familiarity with Java programming, and progresses to discuss advanced topics such as GUI builders, Groovlets, Unit Testing, and Groovy SQL.

Key Features

  • The first comprehensive book on Groovy programming that shows how writing applications and scripts for the Java platform is fast and easy
  • Written by leading software engineers and acclaimed computing instructors
  • Offers numerous programming examples, code samples, detailed case studies, exercises for self-study, and a companion website with a Windows-based Groovy editor


Java programmers and those learning Java. Students learning a programming language for the first time.

Table of Contents




About the authors

Chapter 1: Groovy

1.1 Why Scripting?

1.2 Why Groovy?

Chapter 2: Numbers and Expressions

2.1 Numbers

2.2 Expressions

2.3 Operator Precedence

2.4 Assignment

2.5 Increment and Decrement Operators

2.6 Object References

2.7 Relational and Equality Operators

2.8 Exercises

Chapter 3: Strings and Regular Expressions

3.1 String Literals

3.2 String Indexing and Slicing

3.3 Basic Operations

3.4 String Methods

3.5 String Comparison

3.6 Regular Expressions

3.7 Exercises

Chapter 4: Lists, Maps, and Ranges

4.1 Lists

4.2 List Methods

4.3 Maps

4.4 Map Methods

4.5 Ranges

4.6 Exercises

Chapter 5: Simple Input and Output

5.1 Simple Output

5.2 Formatted Output

5.3 Simple Input

5.4 Exercises

Chapter 6: Case study

6.1 Iteration I: Specification and List Implementation

6.2 Iteration 2: Map Implementation

6.3 Exercises

Chapter 7: Methods

7.1 Methods

7.2 Method Parameters

7.3 Default Parameters

7.4 Method Return Values

7.5 Parameter Passing

7.6 Scope

7.7 Collections as Method Parameters and Return Values

7.8 Exercises

Chapter 8: Flow of Control

8.1 While Statement

8.2 For Statement

8.3 If Statement

8.4 Switch Statement

8.5 Break Statement

8.6 Continue Statement

8.7 Exercises

Chapter 9: Closures

9.1 Closures

9.2 Closures, Collections, and Strings

9.3 Other Closure Features

9.4 Exercises

Chapter 10: Files

10.1 Command Line Arguments

10.2 File Class

10.3 Exercises

Chapter 11: Case study

11.1 Iteration I: Specification and Map Implementation

11.2 Iteration 2: Implementation of a Text-Based User Interface

11.3 Iteration 3: Implementation with Closures

11.4 Exercises

Chapter 12: Classes

12.1 Classes

12.2 Composition

12.3 Exercises

Chapter 13: Case study

13.1 Specification

13.2 Iteration 1: An Initial Model

13.3 Iteration 2: Augment the Model

13.4 Iteration 3: Reinstate the User Interface

13.5 Exercises

Chapter 14: Inheritance

14.1 Inheritance

14.2 Inherited Methods

14.3 Redefined Methods

14.4 Polymorphism

14.5 The Abstract Class

14.6 The Interface Class

14.7 Exercises

Chapter 15: Unit testing (junit)

15.1 Unit Testing

15.2 The Groovytestcase and Junit Testcase Classes

15.3 The Groovytestsuite and Junit Testsuite Classes

15.4 The Role of Unit Testing

15.5 Exercises

Chapter 16: Case study

16.1 Specification

16.2 Iteration 1: Confirm the Polymorphic Effect

16.3 Iteration 2: Demonstrate the Required Functionality

16.4 Iteration 3: Provide User Feedback

16.5 Iteration 4: Enforce Constraints

16.6 Exercises

Chapter 17: Persistence

17.1 Simple Queries

17.2 Relations

17.3 Database Updates

17.4 Objects From Tables

17.5 Inheritance

17.6 The Spring Framework

17.7 Exercises

Chapter 18: Case study

18.1 Iteration 1: Persist the Domain Model

18.2 Iteration 2: The Impact of Persistence

18.3 Exercises

Chapter 19: XML Builders and Parsers

19.1 Groovy Markup

19.2 Markupbuilder

19.3 Xml Parsing

19.4 Exercises

Chapter 20: GUI Builders

20.1 Swingbuilder

20.2 Lists and Tables

20.3 Box and Boxlayout Classes

20.4 Exercises

Chapter 21: Template Engines

21.1 Strings

21.2 Templates

21.3 Exercises

Chapter 22: Case study

22.1 Iteration I: Prototype the Gui

22.2 Iteration 2: Implement the Handlers

22.3 Exercises

Chapter 23: Server-side Programming

23.1 Servlets

23.2 Groovlets

23.3 Gsp Pages

23.4 Exercises

Chapter 24: Case study

24.1 Iteration I: Web Implementation

24.2 Exercise

Chapter 25: Epilogue

Software Distribution

A.1 The Java Development Kit

A.2 The Groovy Development Kit

A.3 Ant

A.4 The Derby/Cloudscape Database

A.5 The Spring Framework

A.6 The Tomcat Server

A.7 Eclipse Ide

A.8 The Textbook Sources


B.1 Simple and Elegant

B.2 Methods

B.3 Lists

B.4 Classes

B.5 Polymorphism

B.6 Closures

B.7 Exceptions

More on Numbers and Expressions

C.1 Classes

C.2 Expressions

C.3 Operator Associativity

C.4 Variable Definitions

C.5 Compound Assignment Operators

C.6 Logical Operators

C.7 Conditional Operator

C.8 Qualified Numeric Literals

C.9 Conversions

C.10 Static Typing

C.11 Testing

More on Strings and Regular Expressions

D.1 Regular Expressions

D.2 Single Character Match

D.3 Match at the Beginning

D.4 Match at the End

D.5 Match Zero or More

D.6 Match One or More

D.7 Match None or One

D.8 Match Number

D.9 Character Classes

D.10 Alternation

D.11 Miscellaneous Notations

D.12 Grouping

More on Lists, Maps, and Ranges

E.1 Classes

E.2 Lists

E.3 Ranges

E.4 The Spread Operator

E.5 Testing

More on Simple Input and Output

F.1 Formatted Output

F.2 Console Class

More on Methods

G.1 Recursive Methods

G.2 Static Typing

G.3 Actual Parameter Agreement

G.4 Method Overloading

G.5 Default Parameter Ambiguity

G.6 Collections as Method Parameters and Return Values

More on Closures

H.1 Closures and Ambiguity

H.2 Closures and Methods

H.3 Default Parameters

H.4 Closures and Scope

H.5 Recursive Closures

H.6 Static Typing

H.7 Actual Parameter Agreement

H.8 Closures, Collections, and Ranges

H.9 Return Statement

H.10 Testing

More on Classes

I.1 Properties and Visibility

I.2 Object Navigation

I.3 Static Members

I.4 Operator Overloading

I.5 The Invokemethod

I.6 Exercises

Advanced Closures

J.1 Simple Closures

J.2 Partial Application

J.3 Composition

J.4 Patterns of Computation

J.5 Business Rules

J.6 Packaging

J.7 List Reduction

J.8 Exercises

More on Builders

K.1 Antbuilder

K.2 Specialized Builders

More on GUI Builders

L.1 Menus and Toolbars

L.2 Dialogs




No. of pages:
© Morgan Kaufmann 2007
Morgan Kaufmann
eBook ISBN:
Paperback ISBN:

About the Author

Kenneth Barclay

Affiliations and Expertise

Napier University, Edinburgh, United Kingdom

John Savage

Affiliations and Expertise

Napier University, Edinburgh, United Kingdom


"For those new to programming, object-orientation, or dynamic languages in general, this book is fabulous!" —Andrew Glover, CTO, Vanward Technologies