Dierk Koenig is a senior software developer, mentor and coach at Canoo Engineering AG, Basel, Switzerland. He writes for leading magazines on software development and speaks at international conferences. He joined the Groovy project as a committer in 2004. Andrew Glover is the President of Stelligent Incorporated. He actively blogs about software quality at thediscoblog.com and testearly.com. Dr Paul King is Managing Director and Principal Consultant for ASERT, has provided technical and strategic consulting to hundreds of organizations throughout the U.S. and Asia Pacific. Guillaume Laforge is the official Groovy Project Manager and member of the JSR-241 Expert Group standardizing the Groovy Scripting Language. Guillaume is a software architect and Open Source consultant, working for OCTO Technology. Jon Skeet is a software engineer and Groovy enthusiast who specializes in Java and C# development.
foreword xix
preface xx
acknowledgments xxiii
about this book xxv
about the authors xxix
about the title xxxii
about the cover illustration xxxiii
1 Your way to Groovy 1
1.1 The Groovy story 3
What is Groovy? 4
Playing nicely with Java: seamless integration 4
Power in your code: a feature-rich language 6
Community-driven but corporate-backed 9
1.2 What Groovy can do for you 10
Groovy for Java professionals 10
Groovy for script programmers 11
Groovy for pragmatic programmers, extremos, and agilists 12
1.3 Running Groovy 13
Using groovysh for Hello World 14
Using groovyConsole 17
Using groovy 18
1.4 Compiling and running Groovy 19
Compiling Groovy with groovyc 19
Running a compiled Groovy script with Java 20
Compiling and running with Ant 21
1.5 Groovy IDE and editor support 22
IntelliJ IDEA plug-in 23
Eclipse plug-in 24
Groovy support in other editors 24
1.6 Summary 25
Part 1 The Groovy language 27
2 Overture: The Groovy basics 29
2.1 General code appearance 30
Commenting Groovy code 30
Comparing Groovy and Java syntax 31
Beauty through brevity 32
2.2 Probing the language with assertions 33
2.3 Groovy at a glance 36
Declaring classes 36
Using scripts 37
GroovyBeans 38
Handling text 39
Numbers are objects 40
Using lists, maps, and ranges 41
Code as objects: closures 43
Groovy control structures 46
2.4 Groovys place in the Java environment 47
My class is your class 47
GDK: the Groovy library 49
The Groovy lifecycle 50
2.5 Summary 53
3 The simple Groovy datatypes 55
3.1 Objects, objects everywhere 56
Javas type systemprimitives and references 56
Groovys answereverythings an object 57
Interoperating with Javaautomatic boxing and unboxing 59
No intermediate unboxing 60
3.2 The concept of optional typing 61
Assigning types 61
Static versus dynamic typing 62
3.3 Overriding operators 63
Overview of overridable operators 63
Overridden operators in action 65
Making coercion work for you 67
3.4 Working with strings 69
...