wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java bean" Watch "java bean" New topic
Author

java bean

ajse ruku
Ranch Hand

Joined: May 06, 2005
Posts: 194
Hi all,

I want to know why a class having setter and getter method for its variables is called a bean?How it is different from any other java class.
I mean to say if a class has setter and getter method for its variables then is it
handled differently by a framework?What is the role of introspection here?Please express your views?

with regards,
ajse
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Moved to Java in General (beginner)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prasanna Kannan
Greenhorn

Joined: Mar 07, 2005
Posts: 21
Hi Ajse,

Obviously, a bean is not a much different class from an ordinary java class. But, as you have guessed, some (rather many, I guess) frameworks handle the bean differently from normal java class.

One of the good example could be the use of bean classes by the struts framework, where data from the fields of jsp/html files is extracted/filled by the action classes via the getter/setter methods of bean classes.

Regards,
Prasanna
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

You might find this interesting: JavaBean Concepts.

(This is part of a JavaBeans tutorial.)
[ March 30, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Tom Fulton
Ranch Hand

Joined: Mar 30, 2006
Posts: 95
You are correct that there is not much difference between a simple Java class with getters and setters (sometimes called a "value class") and a JavaBean. From a practical standpoint, the design purpose of beans from Sun's perspective is quite different from (in my experience) most developers. For example, these are two quotes from the referenced JavaBean tutorial:

"Components expose their features (for example, public methods and events) to builder tools for visual manipulation."

"All this can be done without writing a line of code."

I have not met a single Java developer who does this as a part of their job. Instead, JavaBeans are more typically used to represent useful entities that don't have a specific GUI representation...their fields' values may be displayed somewhere, in an applet or on a JSP, but the bean itself is not "visually manipulated".

To make matters worse, a JavaBean also has some other requirements that are not strictly followed by developers...the need for a default (no-arg) constructor, and the bean being Serializable.

I am new to this forum, so I wouldn't be surprised to find others disagreeing with my opinion here. But one thing I have determined after teaching Java for some time is that Sun's concept of how something should be used is sometimes quite different from the way in which real developers use that feature.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java bean