Meaningless Drivel is fun!*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

Difference between Normal Java Class and Java Bean

Vasu
Greenhorn

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: 14074
    
  16

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

See: http://en.wikipedia.org/wiki/JavaBean

(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 7 API documentation
Scala Notes - My blog about Scala
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
author
Sheriff

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 sun.com:
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Difference between Normal Java Class and Java Bean
 
Similar Threads
what is the difference between a java bean and a java class?
Java class and Java Bean
JavaBeans Naming Rules
Java Bean
Java