Why use a JavaBean? Why not just classes in a jar file?

T

Tom Dyess

Why would I use a JavaBean for any non-GUI related coding? I currently
package my reusable classes in jar files and it works like a charm. If I
understand correctly, JavaBeans are components similar to components in
Delphi in which a programmer can create a visual/non-visual component and
drop it on a form, such as a CrazySpinButton, or maybe a
CustomOracleConnection. I don't see how or why it would be useful in
designing servlets. Would someone please enlighten me?
 
W

Wendy S

Tom Dyess said:
Why would I use a JavaBean for any non-GUI related coding? I currently
package my reusable classes in jar files and it works like a charm. If I
understand correctly, JavaBeans are components similar to components in
Delphi in which a programmer can create a visual/non-visual component and
drop it on a form, such as a CrazySpinButton, or maybe a
CustomOracleConnection. I don't see how or why it would be useful in
designing servlets. Would someone please enlighten me?

http://java.sun.com/products/javabeans/docs/spec.html
(You want that first 'download' button)
The 'Introduction' section should answer your questions.

When you're talking about Servlets, a JavaBean is nothing special, it's just
"marketing speak" for a plain old Java class that it conforms to a set of
rules, mostly naming conventions. Maybe you have a Person class with
getName and setName methods. If so (and you didn't break any of the rules)
you have a JavaBean.

They're very useful, for instance with JSTL. If you place an instance of
the Person class in the user's request or session, you can do
<c:eek:ut value="${myPerson.name}"/>
and JSTL will find the bean, call getName() on it and display the result.
But if you haven't followed the naming conventions, JSTL and other
bean-aware utilities can't figure out what to do.
 
G

Guest

Why would I use a JavaBean for any non-GUI related coding? I currently
package my reusable classes in jar files and it works like a charm. If I
understand correctly, JavaBeans are components similar to components in
Delphi in which a programmer can create a visual/non-visual component and
drop it on a form, such as a CrazySpinButton, or maybe a
CustomOracleConnection. I don't see how or why it would be useful in
designing servlets. Would someone please enlighten me?

A Java Bean is simply an object with get and / or set methods for each
property. IOW, for every property x there is getX() and setX(). If x is
a boolean, it is also common for isX() instead of getX().

I'm sure most of your reusable classes already follow the Bean conventions.

An Enterprise Java Bean (EJB) is a lot more complicated.

HTH,
La'ie Techie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top