O'Reilly logo

Groovy 2 Cookbook by Luciano Fiandesio, Andrey Adamovich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing less verbose Java Beans with Groovy Beans

Java Beans are very popular among Java developers. A Java Bean is essentially data with little or no behavior (depending on the implementation). Formally, a Java Bean is a Java class that is serializable, has a public no-argument constructor, private fields, and getter and setter methods for accessing the fields. Often, POJO (Plain Old Java Object) and a Java Bean are used interchangeably.

In this recipe, we will show how Groovy can save you from a lot of typing by offering several features for bean class creation built into the language and API.

Getting ready

A typical Java Bean looks like the following code snippet:

public class Student implements Serializable { private Long id; private String name; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required