The moose likes Java in General and the fly likes Difference between Normal Java Class and Java Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Difference between Normal Java Class and Java Bean" Watch "Difference between Normal Java Class and Java Bean" New topic

Difference between Normal Java Class and Java Bean


Joined: Oct 09, 2006
Posts: 9
Pls tell me about Java Bean and Java Class
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15080

A JavaBean is just a normal Java class that conforms to a number of conventions:

- it should have a public default constructor (i.e. a constructor that takes no arguments)
- it should be serializable
- it has getter and setter methods to get and set its properties


(Note, an EJB (Enterprise Java Bean) is something entirely different from a normal JavaBean).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Side note: when you remove the implements Serializable clause, then the JavaBean as described at Wikipedia behaves as an ordinary DTO (Data Transfer Object).

An JavaBean is more than just a data wrapper, you can implement action methods in it to play with the data in it.
[ October 10, 2006: Message edited by: B L Scholtz ]
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
There is also more in the JavaBeans specification: properties can be observable, you can create descriptors for beans etc. pp. Most of that is optional, though.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Who's so kind to update this Wikipedia article?

By the way, I just found this at
What Distinguishes JavaBeans from Java Classes?

Any Java class that adheres to certain conventions regarding property and event interface definitions can be a JavaBean. Beans are Java classes that can be manipulated in a visual builder tool and composed into applications.

Introspection, the process by which a builder tool analyzes how a Bean works, differentiates Beans from typical Java classes. Because Beans are coded with predefined patterns for their method signatures and class definitions, tools that recognize these patterns can "look inside" a Bean and determine its properties and behavior.

Introspection allows a Bean's state to be manipulated at design time�that is, at the time it is being assembled as a part within a larger application. For this to work, method signatures within Beans must follow a certain pattern so that introspection tools recognize how Beans can be manipulated, both at design time and at run time.

In effect, Beans publish their attributes and behaviors through special method signature patterns that are recognized by beans-aware application construction tools. However, these construction tools are not required to build or test your beans. The pattern signatures are easily recognized by human readers, as well as builder tools. One of the first things you'll learn when building beans is how to recognize and construct methods that adhere to these patterns.

Beans should not be used indiscriminately. Beans are best suited to software components intended to be visually manipulated within builder tools. Some functionality, such as the JDBC API, is still best provided through a programmatic or textual interface, rather than a visual manipulation interface.
I agree. Here's the link:
subject: Difference between Normal Java Class and Java Bean
It's not a secret anymore!