Making Java Groovy
Kenneth A. Kousen
Foreword by Guillaume Laforge
  • September 2013
  • ISBN 9781935182948
  • 368 pages
  • printed in black & white

Focuses on the tasks that Java developers must tackle every day.

From the Foreword by Guillaume Laforge, Groovy Project Manager

Making Java Groovy is a practical handbook for developers who want to blend Groovy into their day-to-day work with Java. It starts by introducing the key differences between Java and Groovy—and how you can use them to your advantage. Then, it guides you step-by-step through realistic development challenges, from web applications to web services to desktop applications, and shows how Groovy makes them easier to put into production.

About the Technology

Java is large and powerful, but that size and power carries with it complexity and accumulated inconsistencies. Groovy is an elegant JVM-based dynamic language that gracefully co-exists with Java. It both extends and simplifies Java—and for most Java developers, Groovy is super easy to learn. If you know where to apply it, adding in a little Groovy will make you a better Java developer.

About the book

You don't need the full force of Java when you're writing a build script, a simple system utility, or a lightweight web app—but that's where Groovy shines brightest. This elegant JVM-based dynamic language extends and simplifies Java so you can concentrate on the task at hand instead of managing minute details and unnecessary complexity.

Making Java Groovy is a practical guide for developers who want to benefit from Groovy in their work with Java. It starts by introducing the key differences between Java and Groovy and how to use them to your advantage. Then, you'll focus on the situations you face every day, like consuming and creating RESTful web services, working with databases, and using the Spring framework. You'll also explore the great Groovy tools for build processes, testing, and deployment and learn how to write Groovy-based domain-specific languages that simplify Java development.

Table of Contents detailed table of contents




about this book

about the cover illustration

Part 1 Up to speed with Groovy

1. Why add Groovy to Java?

1.1. Issues with Java

1.1.1. Is static typing a bug or a feature?

1.1.2. Methods must be in a class, even if you don’t need or want one

1.1.3. Java is overly verbose

1.1.4. Groovy makes testing Java much easier

1.1.5. Groovy tools simplify your build

1.2. Groovy features that help Java

1.3. Java use cases and how Groovy helps

1.3.1. Spring framework support for Groovy

1.3.2. Simplified database access

1.3.3. Building and accessing web services

1.3.4. Web application enhancements

1.4. Summary

2. Groovy by example

2.1. Hello, Groovy

2.2. Accessing Google Chart Tools

2.2.1. Assembling the URL with query string

2.2.2. Transmitting the URL

2.2.3. Creating a UI with SwingBuilder

2.3. Groovy Baseball

2.3.1. Database data and Plain Old Groovy Objects

2.3.2. Parsing XML

2.3.3. HTML builders and groovlets

2.4. Summary

3. Code-level integration

3.1. Integrating Java with other languages

3.2. Executing Groovy scripts from Java

3.2.1. Using JSR223 scripting for the Java Platform API

3.2.2. Working with the Groovy Eval class

3.2.3. Working with the GroovyShell class

3.2.4. Calling Groovy from Java the easy way

3.2.5. Calling Java from Groovy

3.3. Summary

4. Using Groovy features in Java

4.1. Treating POJOs like POGOs

4.2. Implementing operator overloading in Java

4.3. Making Java library classes better: the Groovy JDK

4.4. Cool AST transformations

4.4.1. Delegating to contained objects

4.4.2. Creating immutable objects

4.4.3. Creating singletons

4.5. Working with XML

4.6. Working with JSON data

4.7. Summary

Part 2 Groovy tools

5. Build processes

5.1. The build challenge

5.2. The Java approach, part 1: Ant

5.3. Making Ant Groovy

5.3.1. The <groovy> Ant task

5.3.2. The <groovyc> Ant task

5.3.3. Writing your build in Groovy with AntBuilder

5.3.4. Custom build scripts with Gant

5.3.5. Ant summary

5.4. The Java approach, part 2: Maven

5.4.1. The Groovy-Eclipse plugin for Maven

5.4.2. The GMaven project

5.4.3. Maven summary

5.5. Grapes and @Grab

5.6. The Gradle build system

5.6.1. Basic Gradle builds

5.6.2. Interesting configurations

5.7. Summary

6. Testing Groovy and Java projects

6.1. Working with JUnit

6.1.1. A Java test for the Groovy implementation

6.1.2. A Groovy test for the Java implementation

6.1.3. A GroovyTestCase test for a Java implementation

6.2. Testing scripts written in Groovy

6.2.1. Useful subclasses of GroovyTestCase: GroovyShellTestCase

6.2.2. Useful subclasses of GroovyTestCase: GroovyLogTestCase

6.3. Testing classes in isolation

6.3.1. Coerced closures

6.3.2. The Expando class

6.3.3. StubFor and MockFor

6.4. The future of testing: Spock

6.4.1. The Search for Spock

6.4.2. Test well, and prosper

6.4.3. Data-driven specifications

6.4.4. The trouble with tribbles

6.4.5. Other Spock capabilities

6.5. Summary

Part 3 Groovy in the real world

7. The Spring framework

7.1. A Spring application

7.2. Refreshable beans

7.3. Spring AOP with Groovy beans

7.4. Inline scripted beans

7.5. Groovy with JavaConfig

7.6. Building beans with the Grails BeanBuilder

7.7. Summary

8. Database access

8.1. The Java approach, part 1: JDBC

8.2. The Groovy approach, part 1: groovy.sql.Sql

8.3. The Java approach, part 2: Hibernate and JPA

8.4. The Groovy approach, part 2: Groovy and GORM

8.4.1. Groovy simplifications

8.4.2. Grails Object-Relational Mapping (GORM)

8.5. Groovy and NoSQL databases

8.5.1. Populating Groovy vampires

8.5.2. Querying and mapping MongoDB data

8.6. Summary

9. RESTful web services

9.1. The REST architecture

9.2. The Java approach: JAX-RS

9.2.1. JAX-RS resource and tests

9.3. Implementing JAX-RS with Groovy

9.4. RESTful Clients

9.5. Hypermedia

9.5.1. A simple example: Rotten Tomatoes

9.5.4. Using a JsonBuilder to control the output

9.6. Other Groovy approaches

9.6.1. Groovlets

9.6.2. Ratpack

9.6.3. Grails and REST

9.7. Summary

10. Building and testing web applications

10.1. Groovy servlets and ServletCategory

10.2. Easy server-side development with groovlets

10.2.1. A "Hello, World!" groovlet

10.2.2. Implicit variables in groovlets

10.3. Unit-and integration-testing web components

10.3.1. Unit-testing servlets with Spring

10.3.2. Integration testing with Gradle

10.3.3. Automating Jetty in the Gradle build

10.3.4. Using an integration-test source tree

10.4. Grails: the Groovy "killer app"

10.4.1. The quest for the holy Grails

10.5. Summary

Appendix A: Installing Groovy

A.1. Installing a JDK

A.2. Installing Groovy

A.3. Testing your installation

A.4. IDE support

A.5. Installing other projects in the Groovy ecosystem

Appendix B: Groovy by feature

B.1. Scripts and the traditional example

B.2. Variables, numbers, and strings

B.2.1. Numbers

B.2.2. Strings and Groovy strings

B.3. Plain Old Groovy Objects

B.4. Collections

B.4.1. Ranges

B.4.2. Lists

B.4.3. Maps

B.5. Closures

B.6. Loops and conditionals

B.6.1. Loops

B.6.2. Conditionals

B.6.3. Elvis

B.6.4. Safe de-reference

B.7. File I/O

B.8. XML

B.8.1. Parsing and slurping XML

B.8.2. Generating XML

B.8.3. Validation

B.9. JSON support

B.9.1. Slurping JSON

B.9.2. Building JSON

Appendix C: Soap-based web services — online only

C.1. A quick review of SOAP and WSDL

C.1.1. SOAP

C.1.2. WSDL

C.2. Building a Groovy web service client

C.2.1. The Global Weather web service

C.2.2. Generating the stubs

C.2.3. Building the Groovy client

C.3. Building a web service in Java and Groovy

C.3.1. A Java SIB for the Calculator

C.3.2. Implementing the SIB in Groovy

C.3.3. Splitting the interface from the implementation

C.3.4. A nontrivial domain model

C.4. Processing XML messages with web service handlers

C.4.1. SOAP handler in Java

C.4.2. Using Groovy for XML manipulation

C.5. Gradle tasks for wsimport and wsgen


What's inside

  • Easier Java
  • Closures, builders, and metaprogramming
  • Gradle for builds, Spock for testing
  • Groovy frameworks like Grails and Griffon

About the reader

Written for developers familiar with Java. No Groovy experience required.

About the author

Ken Kousen is an independent consultant and trainer specializing in Spring, Hibernate, Groovy, and Grails.

placing your order...

Don't refresh or navigate away from the page.
print book $29.99 $44.99 pBook + eBook + liveBook
Additional shipping charges may apply
Making Java Groovy (print book) added to cart
continue shopping
go to cart

eBook $24.99 $35.99 3 formats + liveBook
Making Java Groovy (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.

FREE domestic shipping on three or more pBooks