ebook img

Learning Groovy PDF

116 Pages·2016·11.79 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learning Groovy

Learning Groovy — Adam L. Davis Learning Groovy Adam L. Davis Learning Groovy Adam L. Davis New York, USA ISBN-13 (pbk): 978-1-4842-2116-7 ISBN-13 (electronic): 978-1-4842-2117-4 DOI 10.1007/978-1-4842-2117-4 Library of Congress Control Number: 2016949453 Copyright © 2016 by Adam L. Davis This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. Cover image designed by Freepik While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director: Welmoed Spahr Lead Editor: Steve Anglin Technical Reviewer: Manuel Jordan Elera Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Celestin Suresh John, Nikhil Karkal, James Markham, Susan McDermott, Matthew Moodie, Natalie Pao, Gwenan Spearing Coordinating Editor: Mark Powers Copy Editor: Kezia Endsley Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected] , or visit w ww.springeronline.com . Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected] , or visit w ww.apress.com . Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales . Any source code or other supplementary materials referenced by the author in this text are available to readers at w ww.apress.com/9781484221167 . For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/ . Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter. Printed on acid-free paper To my parents, to whom I owe everything in ways large and small. To my children, who mean the world to me. To my wife, for putting up with me and supporting me. Contents at a Glance About the Author .............................................................................xv About the Technical Reviewer .......................................................xvii Acknowledgments ..........................................................................xix About This Book..............................................................................xxi ■ Part I: Getting Groovy ..................................................... 1 ■ Chapter 1: Software to Install .........................................................3 ■ Chapter 2: Groovy 101 ....................................................................5 ■ Chapter 3: Tools ............................................................................15 ■ Chapter 4: GDK .............................................................................17 ■ Chapter 5: Coming from Java .......................................................23 ■ Part II: Advanced Groovy .............................................. 29 ■ Chapter 6: Groovy Design Patterns ...............................................31 ■ Chapter 7: DSLs ............................................................................35 ■ Chapter 8: Traits ...........................................................................41 ■ Chapter 9: Functional Programming ............................................45 ■ Chapter 10: Groovy GPars .............................................................55 ■ Part III: The Groovy Ecosystem ..................................... 59 ■ Chapter 11: Groovy Awesomeness ...............................................61 ■ Chapter 12: Gradle ........................................................................65 v ■ CONTENTS AT A GLANCE ■ Chapter 13: Grails .........................................................................71 ■ Chapter 14: Spock ........................................................................79 ■ Chapter 15: Ratpack .....................................................................83 ■ Appendix A: Java/Groovy ..............................................................95 ■ Appendix B: Resources .................................................................97 Index ................................................................................................99 vi Contents About the Author .............................................................................xv About the Technical Reviewer .......................................................xvii Acknowledgments ..........................................................................xix About This Book..............................................................................xxi ■ Part I: Getting Groovy ..................................................... 1 ■ Chapter 1: Software to Install .........................................................3 Java/Groovy .............................................................................................3 Trying It Out ..............................................................................................................4 Others ......................................................................................................4 Code on Github ........................................................................................4 ■ Chapter 2: Groovy 101 ....................................................................5 What Is Groovy? ......................................................................................5 Compact Syntax ......................................................................................6 Dynamic def ............................................................................................6 List and Map Defi nitions ..........................................................................6 Groovy GDK ..............................................................................................7 Everything Is an Object ...........................................................................7 Easy Properties .......................................................................................7 GString ....................................................................................................8 Closures ..................................................................................................8 vii ■ CONTENTS A Better Switch .......................................................................................9 Meta-Programming ...............................................................................10 Static Type-Checking .............................................................................10 Elvis Operator ........................................................................................11 Safe Dereference Operator ....................................................................12 A Brief History .......................................................................................12 Groovy 1.8 ...............................................................................................................12 Groovy 2.0 ...............................................................................................................13 Groovy 2.1 ...............................................................................................................13 Groovy 2.2 ...............................................................................................................13 Groovy 2.3 ...............................................................................................................14 Groovy 2.4 ...............................................................................................................14 Summary ...............................................................................................14 ■ Chapter 3: Tools ............................................................................15 Console ..................................................................................................15 Compilation ...........................................................................................15 Shell ......................................................................................................16 Documentation ......................................................................................16 ■ Chapter 4: GDK .............................................................................17 Collections .............................................................................................17 Spread ....................................................................................................................18 GPath ......................................................................................................................18 IO ...........................................................................................................18 Files ........................................................................................................................18 URLs .......................................................................................................................19 Ranges ..................................................................................................20 viii ■ CONTENTS Utilities ..................................................................................................21 Confi gSlurper ..........................................................................................................21 Expando ..................................................................................................................21 ObservableList/Map/Set .........................................................................................22 ■ Chapter 5: Coming from Java .......................................................23 Default Method Values ..........................................................................23 Equals, Hashcode, and More .................................................................23 Regex Pattern Matching ........................................................................24 Missing Java Syntax ..............................................................................25 Semicolon Optional ...............................................................................25 Where Are Generics? .............................................................................26 Groovy Numbers ....................................................................................26 Boolean-Resolution ...............................................................................26 Map Syntax ...........................................................................................27 Summary ...............................................................................................27 ■ Part II: Advanced Groovy .............................................. 29 ■ Chapter 6: Groovy Design Patterns ...............................................31 Strategy Pattern ....................................................................................31 Meta-Programming ...............................................................................32 Meta-Class .............................................................................................................32 Categories ..............................................................................................................32 Missing Methods ...................................................................................33 Delegation .............................................................................................34 ix

Description:
Start building powerful apps that take advantage of the dynamic scripting capabilities of the Groovy language. This book covers Groovy fundamentals, such as installing Groovy, using Groovy tools, and working with the Groovy Development Kit (GDK). You'll also learn more advanced aspects of Groovy, su
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.