A Java Bean is a plain Java class that follows a set of conventions: a public no-argument constructor, private fields exposed through public getter and setter methods, and (traditionally) implementation of java.io.Serializable. These conventions let frameworks, tools and IDEs discover and manipulate an object's properties automatically through reflection. Do not confuse a Java Bean with a Spring bean, which is any object managed by the Spring container.
This guide explains the Java Bean rules, shows a classic bean and its modern record alternative, covers property naming and bound properties, and clarifies how Java Beans differ from POJOs, DTOs and Spring beans. Examples work on Java 17, 21 and 25.
The JavaBeans specification defines these conventions:
getXxx() (or isXxx() for boolean) and setters named setXxx(value).java.io.Serializable, so state can be saved and restored.equals(), hashCode() and toString() implementations, and support for property change events.A property is defined by its accessor methods, not by the field. A getter getName() alone makes a read-only property called name.
Using it looks like ordinary Java:
The setter shows an advantage of encapsulation: validation lives in one place instead of every caller.
The java.beans package can list the properties of any bean using its getter and setter names.
Frameworks such as Spring, Jackson (with default settings), Hibernate and JSP/Jakarta Server Pages rely on this naming convention to read and write data.
Beans can notify listeners when a property changes, using PropertyChangeSupport. This is the basis of the observer style used in desktop UIs.
Register a listener with account.addPropertyChangeListener(e -> System.out.println(e.getPropertyName() + " changed")) and every call to setBalance triggers it.
Since Java 16, a record gives you an immutable data carrier with no boilerplate:
A record has accessors such as name() rather than getName(), and no no-argument constructor or setters, so it is not a Java Bean in the strict sense. Many libraries still support records: Jackson 2.12 and later, and Spring MVC and Spring Data, can bind to them. Use a classic bean when a framework requires mutable properties with getters and setters, and a record for immutable data. Lombok's @Data can generate bean boilerplate, but it is a third-party annotation processor, not part of Java.
| Term | Meaning |
|---|---|
| Java Bean | Class following the getter/setter, no-arg constructor, Serializable convention |
| POJO | Any plain Java object not tied to a framework base class or interface |
| DTO | A bean or record used only to carry data between layers |
| Spring bean | Any object whose lifecycle is managed by the Spring IoC container |
Every Java Bean is a POJO, but a POJO is not necessarily a Java Bean. A Spring bean does not need to follow the JavaBeans conventions at all.
Frameworks create instances through reflection and then populate properties with setters. Without a public no-argument constructor, tools cannot instantiate the class generically.
The specification says it should, but most modern frameworks do not require it. Add Serializable when instances are stored in an HTTP session, cached remotely, or passed through Java serialization.
An Enterprise JavaBean (EJB) is a server-side component managed by a Jakarta EE container, with transactions and security. A Java Bean is just a reusable class following simple conventions.
Not strictly. Records are immutable and use accessor methods without the get prefix, but most libraries can still read and write them.
A Java Bean is a reusable class with a no-argument constructor, private fields, getters and setters, and usually Serializable. The conventions allow frameworks to inspect and bind properties automatically. Prefer records for immutable data in new Java code, keep classic beans where a framework needs mutable properties, and do not confuse them with Spring beans or EJBs.