Groovy in Action
eBook - ePub

Groovy in Action

Cédric Champeau, Dierk Koenig, Hamlet D'Arcy, Paul King

Condividi libro
  1. 912 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Groovy in Action

Cédric Champeau, Dierk Koenig, Hamlet D'Arcy, Paul King

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Summary Groovy in Action, Second Edition is a thoroughly revised, comprehensive guide to Groovy programming. It introduces Java developers to the dynamic features that Groovy provides, and shows how to apply Groovy to a range of tasks including building new apps, integration with existing code, and DSL development. Covers Groovy 2.4.Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology In the last ten years, Groovy has become an integral part of a Java developer's toolbox. Its comfortable, common-sense design, seamless integration with Java, and rich ecosystem that includes the Grails web framework, the Gradle build system, and Spock testing platform have created a large Groovy community About the Book Groovy in Action, Second Edition is the undisputed definitive reference on the Groovy language. Written by core members of the Groovy language team, this book presents Groovy like no other can—from the inside out. With relevant examples, careful explanations of Groovy's key concepts and features, and insightful coverage of how to use Groovy in-production tasks, including building new applications, integration with existing code, and DSL development, this is the only book you'll need. Updated for Groovy 2.4.Some experience with Java or another programming language is helpful. No Groovy experience is assumed. What's Inside

  • Comprehensive coverage of Groovy 2.4 including language features, libraries, and AST transformations
  • Dynamic, static, and extensible typing
  • Concurrency: actors, data parallelism, and dataflow
  • Applying Groovy: Java integration, XML, SQL, testing, and domain-specific language support
  • Hundreds of reusable examples


About the Authors
Authors Dierk König, Paul King, Guillaume Laforge, Hamlet D'Arcy, Cédric Champeau, Erik Pragt, and Jon Skeet are intimately involved in the creation and ongoing development of the Groovy language and its ecosystem.
Table of Contents
PART 1 THE GROOVY LANGUAGE

  • Your way to Groovy
  • Overture: Groovy basics
  • Simple Groovy datatypes
  • Collective Groovy datatypes
  • Working with closures
  • Groovy control structures
  • Object orientation, Groovy style
  • Dynamic programming with Groovy
  • Compile-time metaprogramming and AST transformations
  • Groovy as a static language
  • PART 2 AROUND THE GROOVY LIBRARY
  • Working with builders
  • Working with the GDK
  • Database programming with Groovy
  • Working with XML and JSON
  • Interacting with Web Services
  • Integrating Groovy
  • PART 3 APPLIED GROOVY
  • Unit testing with Groovy
  • Concurrent Groovy with GPars
  • Domain-specific languages
  • The Groovy ecosystem

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Groovy in Action è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Groovy in Action di Cédric Champeau, Dierk Koenig, Hamlet D'Arcy, Paul King in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Programming in Java. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Editore
Manning
Anno
2015
ISBN
9781638352877

Part 1. The Groovy language

A good notation has subtlety and suggestiveness which at times makes it almost seem like a live teacher.
Bertrand Russell The World of Mathematics (1956)
Learning a new programming language is comparable to learning to speak a foreign language. You have to deal with new vocabulary, grammar, and language idioms. But this initial effort pays off multiple times. With the new language, you find unique ways to express yourself, you’re exposed to new concepts and styles that add to your personal abilities, and you may even explore new perspectives on your world. This is what Groovy did for us, and we hope Groovy will do it for you, too.
The first part of this book introduces you to the language basics: the Groovy syntax, grammar, and typical idioms. We present the language by example as opposed to using an academic style.
You may skim this part on first read and revisit it before going into serious development with Groovy. If you decide to skim, please make sure you visit chapter 2 and its examples. They are cross-linked to the in-depth chapters so you can easily look up details about any topic that interests you.
One of the difficulties of explaining a programming language by example is that you have to start somewhere. No matter where you start, you end up needing to use some concept or feature that you haven’t explained yet for your examples. Section 2.3 serves to resolve this perceived deadlock by providing a collection of self-explanatory warm-up examples.
We explain the main portion of the language using its built-in datatypes and introduce expressions, operators, and keywords as we go along. By starting with some of the most familiar aspects of the language and building up your knowledge in stages, we hope you’ll always feel confident when exploring new territory.
Chapter 3 introduces Groovy’s practical approach to typing, examines the numeric and other primitive types that Groovy supports, and discusses strings and regular expressions.
Chapter 4 continues looking at Groovy’s rich set of built-in types, examining those with a collection-like nature: ranges, lists, and maps.
Chapter 5 builds on the preceding sections and provides an in-depth description of the closure concept.
Chapter 6 touches on logical branching, looping, and shortcutting program execution flow.
Chapter 7 sheds light on the way Groovy builds on Java’s object-oriented features adding support for multimethods and traits.
Chapter 8 looks at Groovy’s dynamic programming capabilities.
Chapter 9 dives into compile-time metaprogramming and AST transformations.
Chapter 10, the final chapter in part 1, discusses Groovy as a static language.
At the end of part 1, you’ll have the whole picture of the Groovy language. This is the basis for getting the most out of part 2, which explores the Groovy library: the classes and methods that Groovy adds to the Java platform. Part 3, “Applied Groovy,” leads you through places where the power of Groovy is put into action.

Chapter 1. Your way to Groovy

This chapter covers
  • What Groovy is all about
  • How it makes your programming life easier
  • How to start
It isn’t the mountains ahead to climb that wear you out; it’s the pebble in your shoe.
Muhammad Ali
You’ve heard of Groovy, maybe even installed the distribution and tried snippets from the online tutorials. Perhaps your project has adopted Groovy as a dynamic extension to Java and you now seek information about what you can do with it. You may have been acquainted with Groovy from using the Grails web application platform, the Griffon desktop application framework, the Gradle build system, or the Spock testing facility, and now look for background information about the language that these tools are built upon. This book delivers to that purpose, but you can expect even more from learning Groovy.
Groovy will give you quick wins, whether by making your Java code simpler to write, by automating recurring tasks, by modeling business logic in domain-specific languages (DSLs), or by supporting ad-hoc scripting for your daily work as a programmer. It’ll give you longer-term wins by making your code simpler to read. Perhaps most important, it’s a pleasure to use.
Learning Groovy is a wise investment. Groovy brings the power of advanced language features such as closures, dynamic methods, and the Meta Object Protocol (MOP) to the Java platform. Your Java knowledge will not become obsolete by walking the Groovy path. Groovy will build on your experience and familiarity with the Java platform, allowing you to pick and choose when you use which tool—and when to combine the two seamlessly.
Groovy follows a pragmatic “no drama”[1] approach: it obeys the Java object model and always keeps the perspective of a Java programmer. It doesn’t force you into any new programming paradigm, but offers those advanced capabilities that you legitimately expect from a “top-of-stack” language.
1 Thanks to Mac Liaw for this wording.
This first chapter provides background information about Groovy and everything you need to know to get started. It starts with the Groovy story: why Groovy was created, what considerations drive its design, and how it positions itself in the landscape of languages and technologies. The next section expands on Groovy’s merits and how they can make life easier for you, whether you’re a Java programmer, a script aficionado, or an agile developer.
We strongly believe that there’s only one way to learn a programming language: by trying it. We present a variety of scripts to demonstrate the compiler, interpreter, and shells, before listing plug-ins available for widely used IDEs and where to find the latest information about Groovy.
By the end of this chapter, you’ll have a basic understanding of what Groovy is and how you can experiment with it.
We—the authors, the reviewers, and the editing team—wish you a great time programming Groovy and using this book for guidance and reference.

1.1. The Groovy story

At Groovy One 2004—a gathering of Groovy developers in London—James Strachan gave a keynote address telling the story of how he arrived at the idea of inventing Groovy.
He and his wife were waiting for a late plane. While she went shopping, he visited an internet cafe and spontaneously decided to go to the Python website and study the language. In the course of this activity, he became more and more intrigued. Being a seasoned Java programmer, he recognized that his home language lacked many of the interesting and useful features Python had invented, such as native language support for common datatypes...

Indice dei contenuti