Leanpub Header

Skip to main content

Retired

This book is no longer available for sale.

Learning Groovy

A guide to learning the popular JVM programming language, Groovy 2.x, and its ecosystem

Now at Apress. An ebook to help programmers learn Groovy, a flexible open-source language built for the JVM (Java Virtual Machine), and the Groovy ecosystem. This book covers Groovy basics, Gradle, Grails, Spock, Groovy design patterns, advanced Groovy programming, Ratpack, and more. Now at Apress

PDF
EPUB
WEB
104
Pages
15,598Words
About

About

About the Book

Who is this book for?

Although this book is somewhat intended for those with a Java background, anyone with basic programming skills could benefit from it. This book is a data-filled, yet easy-to-digest tour of the Groovy language and ecosystem. Now at Apress

This book covers:

  • Groovy basics, including the GDK
  • Advanced Groovy, such as writing Groovy DSLs
  • Functional programming in Groovy
  • GPars, the built-in concurrency library
  • Gradle, the build system
  • Grails, the web application framework
  • Spock, the testing framework
  • Ratpack, the reactive web library

Groovy is a flexible open-source language built for the JVM (Java Virtual Machine) with a Java-like syntax. It can be used dynamically or statically-typed, your choice. It supports functional programming constructs, including first-class functions, currying, and more. It has multiple-inheritance, type inference, and meta-programming. 

Groovy is very similar in syntax to Java so it is generally easy for Java developers to learn (Java code is generally valid Groovy code).  However, Groovy has many additional features and relaxed syntax rules: closures, dynamic typing, meta-programming (via metaClass), semicolons are optional, regex-support, operator overloading, GStrings, and more. Groovy is interpreted at runtime, but in Groovy 2.0 the ability to compile to byte-code and enforce type-checking were added to the language.

Praise for previous works:

If you're just getting to Java 8, I definitely recommend @adamldavis' book -- very concise and helpful. -Fred Jonsson

"bought both of your books (Modern Java & Modern Programming) and let me tell you, what a great value and extremely good content" - Rozzot

Author

About the Author

Adam L. Davis

Adam Davis makes software. He's spent many years developing in Java (since Java 1.2) and has enjoyed using Spring, Hibernate, Grails, and many others. He has used Java, Groovy, JavaScript, AWS, and much more to build applications for over a decade and has worked at both large and small corporations. Adam is a Certified Spring Professional and has a Masters and a Bachelors degree in Computer Science from Georgia Tech.

http://adamldavis.com

Contents

Table of Contents

Getting Groovy

  1. About This Book

Software to Install

  1. Java/Groovy
  2. Others
  3. Code on Github

Groovy 101

  1. What is Groovy?
  2. Compact Syntax
  3. Dynamic Def
  4. List and Map Definitions
  5. Groovy GDK
  6. Everything is an Object
  7. Easy Properties
  8. GString
  9. String
  10. Closures
  11. Return Optional
  12. Closure Exercise
  13. A Better Switch
  14. Meta-programming
  15. Static Type Checking
  16. Elvis Operator
  17. Safe Dereference Operator
  18. A Brief History
  19. Summary

Tools

  1. Console
  2. Compilation
  3. Shell
  4. Documentation

GDK

  1. Collections
  2. IO
  3. Ranges
  4. Utilities

Coming from Java

  1. Default Method Values
  2. Equals, Hashcode, etc.
  3. Regex Pattern Matching
  4. Missing Java Syntax
  5. Semi-colon Optional
  6. Where are Generics?
  7. Groovy Numbers
  8. Boolean-resolution
  9. Map Syntax
  10. Summary
  11. Advanced Groovy

Groovy Design Patterns

  1. Strategy Pattern
  2. Meta-programming
  3. Method Missing
  4. Delegation

DSLs

  1. Delegate
  2. Overriding Operators
  3. Method-missing and Property-missing

Traits

  1. Defining Traits
  2. Using Traits
  3. Summary

Functional Programming

  1. Functions and Closures
  2. Map/Filter/etc.
  3. Immutability
  4. Groovy Fluent GDK
  5. Groovy Curry
  6. Method Handles
  7. Tail Recursion
  8. Summary

Groovy GPars

  1. Parallel Map Reduce
  2. Actors
  3. The Groovy Ecosystem

Groovy Awesomeness

  1. Web and UI Frameworks
  2. Cloud Computing Frameworks
  3. Build Frameworks
  4. Testing Frameworks/Code Analysis
  5. Concurrency
  6. Others

Gradle

  1. Projects and Tasks
  2. Plugins
  3. Configuring a Task
  4. Extra Configuration
  5. Maven Dependencies
  6. Gradle Properties
  7. Multiproject builds
  8. File Operations
  9. Exploring
  10. Summary
  11. Online Documentation

Grails

  1. What is Grails?
  2. Quick Overview of Grails
  3. Plugins
  4. REST in Grails
  5. Short History of Grails
  6. Testing
  7. Cache Plugin
  8. Grails Wrapper
  9. Cloud
  10. Only an Overview
  11. Groovy Mailgun

Spock

  1. Introduction
  2. A Simple Test
  3. Mocking
  4. Lists or Tables of Data
  5. Ranges
  6. Expecting Exceptions
  7. Conclusion

Ratpack

  1. Script
  2. Gradle
  3. Ratpack Layout
  4. Handlers
  5. Rendering
  6. JSON
  7. Bindings
  8. Blocking
  9. Configuration
  10. Testing
  11. Summary
  12. Appendixes

Java/Groovy4

Resources

Causes

Causes Supported

Oxfam America

Oxfam America

Right the Wrong

http://www.oxfamamerica.org
Oxfam America is a global organization working to right the wrongs of poverty, hunger, and injustice. We save lives, develop long-term solutions to poverty, and campaign for social change. As one of 17 members of the international Oxfam confederation, we work with people in more than 90 countries to create lasting solutions.
Oxfam America is a global organization working to right the wrongs of poverty, hunger, and injustice. We save lives, develop long-term solutions to poverty, and campaign for social change. As one of 17 members of the international Oxfam confederation, we work with people in more than 90 countries to create lasting solutions. Our vision: A just world without poverty. Our mission: To create lasting solutions to poverty, hunger, and social injustice.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub