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?
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.
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.