Different between Bean and Class
1 posts in topic
Flat View  Flat View

Posted By:   karthikeyan_thirunavu
Posted On:   Wednesday, January 14, 2004 02:25 AM

Normally writing a Bean is setting your own property,own let me the exact term of bean and class?

when should call a class is to be a bean?

Re: Different between Bean and Class

Posted By:   Stephen_McConnell  
Posted On:   Wednesday, January 14, 2004 05:11 AM

A little history might be apporpriate here.

When the "Bean" concept first came out in the primordial times of Java, it was used to describe a class that:

  • Had a "no argument constructor".

  • Had properties that were only accessed by get/set.

  • When a property changed (or even accessed), an event was triggered that other objects could listen for and respond appropriately.

These basic features allowed the java reflection api's to instantiate an object and access its properties without having to know specificially what class it was instantiating.

This was good for developing GUI builder IDE's for a start.

Then, along came servlets and JSPs; and these features became very attractive to JSPs. You could create request parameters in your request and the JSP could instantiate a Class, use the "name" of the name/value pair to access the "getter/setters" if they were defined correctly... all behind the scenes.

So, a "bean" became a class with a no-argument constructor and getter/setters to access properties.

Then, you get into Enterprise Java Beans.... which is a whole nother animal....

But to answer your basic question, a Bean is a type of Class that is used to encapsulate information and fits the no-argument constructor and getter/setter criteria.

Do not confuse a Bean, Class and Object... the class is just a template for an Object...

Hope this helps.

Stephen McConnell

BTW, this has been answered several times before in this forum; and a search of the site using the search engine above could find those answers. Good Luck.

About | Sitemap | Contact