Skip Navigation Links

Course Length:
3 Days
Course Description:
Groovy is a dynamic scripting and programming language for the Java platform. It combines the dynamic features of modern scripting languages such as Ruby and Python with familiar Java syntax. To quote one of the Groovy developers: “Groovy is what Java would have been if it had been created in the 21st century.” This course introduces the Java developer to the Groovy language. The course focuses on understanding the internals of how Groovy works in addition to understanding the Groovy language syntax. After taking this course developers will understand the Groovy syntax and be able to leverage existing Java classes within Groovy. This class combines lecture with a unifying, hands-on experience, and open discussion that will help the developer quickly understand the benefits of Groovy and how to use the language.
Who Should Attend:
This class is for Java developers who wish to learn the Groovy scripting and programming language.
Benefits of Attendance:
Upon completion of this course, students will be able to:
  • Write applications using Groovy.
  • Understand how Groovy operates within the Java Virtual Machine.
  • Incorporate existing Java classes and libraries within Groovy applications.
  • Learn to add new methods and member variable to existing Java or Groovy classes dynamically.
  • Understand the role of Closures within Groovy.
  • Take advantage of Groovy’s simplified object configuration syntax.
  • Learn how to override operators for Groovy or Java classes.
  • Understand the concept of Metaprogramming and how to leverage it to simplify application development.
  • Explore Groovy’s Regular Expression syntax for easily managing String processing.
Prerequisites:
Participants should have taken the Software Development for Non-Programmers course or have a solid understanding of Java programming.
Course Outline:
  • Language Overview
    1. What is Groovy?
    2. What Groovy can do
    3. Java programmers
    4. Script programmers
    5. Agile programming
    6. Installing
    7. Running Groovy scripts
  • Basic Syntax and Scalar Variables
    1. Syntax rules
    2. Numbers - Integers, Floats, and BigDecimal
    3. Strings
    4. Double quoted
    5. Single quoted
    6. Here documents
    7. Slash quoted
    8. GStrings
    9. Operators
  • Collections
    1. Lists
    2. Coding a closure
    3. The it parameter
    4. Passing multiple parameters
    5. Naming parameters (the -> operator)
    6. Maps
    7. Ranges
  • Flow Control
    1. If statements
    2. The truth in Groovy
    3. Switch statements
    4. While loops
    5. For loops
    6. Exceptions
  • Classes
    1. Defining classes
    2. File-to-class relationships
    3. Member variables
    4. Automatic getter/setter generation
    5. Default visibility
    6. Safe dereferencing with ? operator
    7. Methods
    8. Optional parameters and default parameters
    9. Operator overloading
    10. Automatic constructor generation
    11. Initializing property values in the constructor
    12. The Closure Groovy class
    13. Coding a method that expects a closure
    14. Calling into the closure
    15. Passing parameters
  • Advanced Classes and Closures
    1. Closures
    2. Using methods as closures
    3. Polymorphic closures
    4. Operator overloading
    5. Metaprogramming
    6. Discovering a class
    7. Discovering fields
    8. Discovering methods
    9. Method resolution
    10. MetaClass
    11. MetaProperty
    12. MetaMethod
    13. Pointers
    14. Method
    15. Field
    16. Calling methods that do not exist
    17. ExpandoMetaClass
    18. Categories
  • Regular Expressions
    1. Regular Expression syntax
    2. The =~ operator
    3. The ==~ operator
    4. Common methods that use Regular Expressions
  • Builders and Slurpers
    1. What are Builders and Slurpers?
    2. NodeBuilder
    3. MarkupBuilder
    4. AntBuilder
    5. Creating custom builders
    6. Using the ConfigSlurper
    7. Writing a Slurper