Groovy 2 Cookbook
eBook - ePub

Groovy 2 Cookbook

  1. 394 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

About this book

In Detail

Get up to speed with Groovy, a language for the Java Virtual Machine (JVM) that integrates features of both object-oriented and functional programming. This book will show you the powerful features of Groovy 2 applied to real-world scenarios and how the dynamic nature of the language makes it very simple to tackle problems that would otherwise require hours or days of research and implementation.

Groovy 2 Cookbook contains a vast number of recipes covering many facets of today's programming landscape. From language-specific topics such as closures and metaprogramming, to more advanced applications of Groovy flexibility such as DSL and testing techniques, this book gives you quick solutions to everyday problems.

The recipes in this book start from the basics of installing Groovy and running your first scripts and continue with progressively more advanced examples that will help you to take advantage of the language's amazing features.

Packed with hundreds of tried-and-true Groovy recipes, Groovy 2 Cookbook includes code segments covering many specialized APIs to work with files and collections, manipulate XML, work with REST services and JSON, create asynchronous tasks, and more. But Groovy does more than just ease traditional Java development: it brings modern programming features to the Java platform like closures, duck-typing, and metaprogramming.

In this new book, you'll find code examples that you can use in your projects right away along with a discussion about how and why the solution works. Focusing on what's useful and tricky, Groovy 2 Cookbook offers a wealth of useful code for all Java and Groovy programmers, not just advanced practitioners.

Approach

This book follows a Cookbook style and is packed with intermediate and advanced level recipes.

Who this book is for

This book is for Java developers who have an interest in discovering new ways to quickly get the job done using a new language that shares many similarities with Java. The books recipes start simple, therefore no previous Groovy experience is required to understand the code and the explanations accompanying the examples.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Groovy 2 Cookbook


Table of Contents

Groovy 2 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
The Groovy language
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with Groovy
Introduction
Installing Groovy on Windows
Getting ready
How to do it…
There's more...
Installing Groovy on Linux and OS X
How to do it...
How it works...
There's more...
See also
Executing Groovy code from the command line
How to do it...
How it works...
There's more...
See also
Using Groovy as a command-line text file editor
How to do it...
How it works...
There's more...
See also
Using Groovy to start a server on the command line
How to do it...
See also
Running Groovy with invokedynamic support
Getting ready
How to do it...
There's more...
See also
Building Groovy from source
Getting ready
How to do it...
How it works...
Managing multiple Groovy installations on Linux
Getting ready
How to do it...
How it works...
There's more...
See also
Using groovysh to try out Groovy commands
How to do it...
How it works...
There's more...
Starting groovyConsole to execute Groovy snippets
How to do it...
There's more...
Configuring Groovy in Eclipse
Getting ready
How to do it...
How it works...
There's more...
See also
Configuring Groovy in IntelliJ IDEA
Getting ready
How to do it...
There's more...
2. Using Groovy Ecosystem
Introduction
Using Java classes from Groovy
How to do it...
How it works...
There's more...
See also
Embedding Groovy into Java
Getting ready
How to do it...
How it works...
There's more...
See also
Compiling Groovy code
Getting ready
How to do it...
How it works...
See also
Simplifying dependency management with Grape
Getting ready
How to do it...
How it works...
There's more...
See also
Integrating Groovy into the build process using Ant
Getting ready
How to do it...
How it works...
There's more...
See also
Integrating Groovy into the build process using Maven
Getting ready
How to do it...
How it works...
There's more...
See also
Integrating Groovy into the build process using Gradle
Getting ready
How to do it...
How it works...
There's more...
See also
Generating documentation for Groovy code
Getting ready
How to do it...
How it works...
There's more...
See also
Checking Groovy code's quality with CodeNarc
Getting ready
How to do it...
How it works...
There's more...
See also
3. Using Groovy Language Features
Introduction
Searching strings with regular expressions
Getting ready
How to do it...
There's more...
See also
Writing less verbose Java Beans with Groovy Beans
Getting ready
How to do it...
How it works...
There's more...
Inheriting constructors in Groovy classes
How to do it...
How it works...
Adding the cloning functionality to Groovy Beans
How to do it...
How it works...
There's more...
Defining code as data in Groovy
Getting ready
How to do it...
There's more...
Defining data structures as code in Groovy
Getting ready
How to do it...
How it works...
See also
Implementing multiple inheritance in Groovy
Getting ready
How to do it...
How it works...
There's more...
See also
Adding a functionality to the existing Java/Groovy classes
Getting ready
How to do it...
How it works...
There's more...
See also
Defining type-checking rules for dynamic code
Getting ready
How to do it...
How it works...
There's more...
Adding automatic logging to Groovy classes
How to do it...
How it works...
There's more...
See also
4. Working with Files in Groovy
Introduction
Reading from a file
Getting ready
How to do it...
How it works...
There's more...
See also
Reading a text file line by line
Getting ready
How to do it...
There's more...
See also
Processing every word in a text file
Getting ready
How to do it...
How it works...
There's more...
See also
Writing to a file
Getting ready
How to do it...
How it works...
There's more...
See also
Replacing tabs with spaces in a text file
Getting ready
How to do it...
How it works...
There's more...
See also
Filtering a text file's content
Getting ready
How to do it...
How it works...
There's more...
See also
Deleting a file or directory
Getting ready
How to do it...
How it works...
There's more...
See also
Walking through a directory recursively
Getting ready
How to do it...
How it works...
There's more...
See also
Searching for files
Getting ready
How to do it...
How it works...
There's more...
See also
Changing file attributes on Windows
Getting ready
How to do it...
How it works...
There's more...
Reading data from a ZIP file
Getting ready
How to do it...
How it works...
There's more...
See also
Reading an Excel file
Getting ready
How to do it...
How it works...
See also
Extracting data from a PDF
Getting ready
How to do it...
How it works...
There's more...
See also
5. Working with XML in Groovy
Introduction
Reading XML using XmlSlurper
Getting ready
How to do it...
How it works...
See also
Reading XML using XmlParser
How...

Table of contents

  1. Groovy 2 Cookbook

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Groovy 2 Cookbook by Andrey Adamovich, Luciano Fiandesio in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation Open Source. We have over one million books available in our catalogue for you to explore.