I am familiar with J2SE programming.I have been reading the JavaBeans Tutorial at Sun. As I am going through it I am not able to understand one thing.Exactly what are these JavaBeans used for? On resources which I have gone through give examples with a GUI. If its true that its used for building GUI, then why do we need JavaBeans when a powerful libraries such as Swing or others are available.What advantage does they have? To be honest, I have understood nothing from the tutorial till now. Also, the tutorial mentions words like Component Model and Component architecture which I am only vaguely familiar with.Can you kindly directly me to some resources that explain these terms more clearly with the help of some examples. Please correct and guide me if wrong.
A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Joke names and "handles" aren't acceptable here. Many people won't answer your questions until you comply with the naming policy. You can change your display name here. Thanks for your cooperation. [ October 27, 2005: Message edited by: Ernest Friedman-Hill ]
Java Beans were originally invented as pluggable user-interface components. So besides the standard buttons, list boxes, etc. somebody could for example create a chart control as a Java Bean, and others could use this in a visual GUI building environment to point and click a GUI application together.
However, that way of using Java Beans never became really popular.
A Java Bean is just another Java class with get...() and set...() methods to access its member variables. That's basically all there is to it, and that's how most people are using Java Beans today.
EJB (Enterprise Java Beans) is something completely different - it's a bit confusing that those also have "Beans" in the name.
Java bean "components" are similar in purpose to Microsoft's ActiveX/COM components. Pluggable components for user interface "controls" are certainly one application of Java beans, but they're not the only - and probably aren't even the most important - application. Any "unit of functionality" you can wrap in "a software IC" is a good candidate for a "Java Bean".
And no, "Java beans" have nothing whatsoever to do with "Enterprise Java Beans" (sigh!). Enterprise Java Beans (Session beans, Entity beans, etc) are architectural components of a J2EE application. Java beans are implementation components for ordinary J2SE applications. As such, Java beans can be used in any of J2ME, J2SE and/or J2EE. Enterprise Beans, on the other hand, are limited exclusively to J2EE.
Confusing, but I hope that helps a little!
Your .. PSM
Paul M. Santa Maria, SCJP
Joined: Oct 27, 2005
I have not confused EJB with JavaBeans. Reading the replies then is it true that unless I am working as a vendor for delivering pluggable components I don't need to care about JavaBeans?
Paul Santa Maria
Joined: Feb 24, 2004
Hi, again -
1. Sorry: I didn't mean to imply that you confused Java Beans and Enterprise Java Beans. I just wanted to agree with - and to emphasize - Jesper de Jong's very good, very important point that "JB != EJB". No offense!
2. I believe Java Beans are for everybody.
Not only should you know about Java Beans (to use them effectively as the need arises), I would go further and suggest that you should use Java beans yourself, wherever and whenever possible.
One of your primary goals in OO programming is to "encapsulate" your "functionality", to "hide" your "implementation" as thoroughly as possible.
I would argue that both COM/ActiveX and Java Beans are good and useful technologies for doing this. I would further argue that the discipline in coding your Java "class" as a viable "Java Bean" will generally yield cleaner, more robust implementations.
I would definitely encourage you to include "Java Beans" in your Java programming toolbox! [ October 27, 2005: Message edited by: Paul Santa Maria ]
Joined: Dec 06, 2001
Most, if not all, of the classes in the Swing and AWT APIs are JavaBeans. So this is one use for the JavaBean standard. However, you can use JavaBeans wherever it might be appropriate in your programs, even if it doesn't apply to GUI programming.
Beans are also used in the context of web programming. If you delve into JSP, JSP and Struts, you'll find them everywhere, and it becomes important that you understand how their values get assigned through setters/getters.