By Boris Feldman
1. What are JavaBeans?
Created by Sun Microsystems, with input from a number of Java tools vendors, JavaBeans are an API for reusable Java-based components. Using JavaBeans, Java developers can take advantage of component software development technology while still benefiting from Java's promise of hardware independence.
2. Are JavaBeans a standard?
JavaBeans are a public API published by Sun. However, JavaBeans have been neither approved by, nor are under the control of, any independent standards body.
3. On which platforms can I use JavaBeans?
Because JavaBeans are just Java classes written to a specific standard, you can use them on any platform for which there is a Java Virtual Machine that supports JDK 1.1–compatible programs. This means that Windows, Macintosh, and most flavors of Unix can run Java programs that take advantage of JavaBeans.
4. Do I need special software to create or use JavaBeans?
Although you don't need special tools to create JavaBeans, software that is JavaBean-aware will probably make the process easier. In addition, some development environments, especially those that allow for WYSIWYG layout of controls, need to be specifically aware of JavaBeans in order for you to be able to use JavaBean components similarly to built-in controls. In fact, using JavaBeans in an IDE that supports them is as easy as dragging a JavaBean from a component palette into your project in a way similar to that popularized by Microsoft Visual Basic. For example, both Symantec's Visual Café and Borland/Inprise's JBuilder make working with and creating JavaBeans a breeze. Other tools, such as Microsoft's Visual J++, IBM's VisualAge for Java, and Sybase's PowerJ also support JavaBeans to varying degrees.
5. What's the difference between Java applets and JavaBean components?
Both JavaBeans and applets are Java classes, but they are designed with different purposes in mind. An applet is a mini-application that is designed to run inside a browser, whereas a JavaBean is a component coded to a specific standard that is designed to be used within an application or an applet. While it is possible to create a wrapper to turn an applet into a JavaBean, or vice-versa, this conversion is usually unnecessary because the two serve different purposes.
6. I own Microsoft Visual Studio. Can I use JavaBeans with Microsoft J++?
Visual J++ 6.0 does not support JavaBeans natively. However, if you really need to use JavaBean components in your J++ application, you can use a provided conversion tool that turns a JavaBean component into an ActiveX control. Once the conversion is completed, J++'s WFC Designer will be able to host the component and treat it like any other ActiveX control.
7. How do JavaBeans compare to ActiveX controls?
At a high level, the main difference between JavaBeans and ActiveX controls is that while JavaBeans are platform-independent, ActiveX controls can only be used on Windows platforms. So while it's certainly possible to write ActiveX controls using the Java programming language, because of ActiveX's dependence on Microsoft's COM (Component Object Model), those controls will still be limited to Windows-based systems.
8. Can I use ActiveX controls as if they were JavaBeans?
Although using ActiveX controls is possible with some Java compilers this probably isn't a good idea. One of Java's strengths is its ability to work across platforms. JavaBeans can be used regardless of platform; however, using an ActiveX control in a Java project (wrapped as a JavaBean or not) limits your application to environments that support ActiveXnamely Windows.
9. Do I have to use Java to create JavaBeans or will C/C++ or Visual Basic work?
JavaBeans are actually Java classes and thus have to be written in Java. That said, it should certainly be possible to create a wrapper for an ActiveX control to make it pretend to be a JavaBean for the sake of interoperability with JavaBean-dependent systems. Clearly, however, this would just be a workaround and would not really exploit all of the potential of the JavaBean API.
10. If I write a program that uses JavaBeans how do I make sure that my users have the right components on their machine?
You can package one or more JavaBeans into a special JAR file that the Java class loader will automatically download to the user's machine if needed. JAR files are ZIP files that you can use to compress one or more related JavaBeans and any associated files for downloading to a user's machine as a package. JAR files differ from regular ZIP files only in that they must include a file named MANIFEST that acts as the JAR's table of contents.
11. What are the differences between JavaBeans and Enterprise JavaBeans?
JavaBeans were originally designed for user-interface and client-side tasks. To allow for server-side, component-based development in Java, Sun has released the Enterprise JavaBeans (EJB) specification that adds server-side features such as transactions, persistence, and scalability.
12. How do Enterprise JavaBeans compare to Microsoft's Transaction Server?
In many ways the Enterprise JavaBeans architecture competes directly with Microsoft's Transaction Server (MTS). Both MTS and server applications that conform to the EJB specification provide similar functionality for COM-based ActiveX controls and Java-based components, respectively.
13. Are Enterprise JavaBeans compatible with CORBA (Common Object Request Broker Architecture)?
Yes. The Enterprise JavaBeans API specifically spells out EJB's compatibility with CORBA.
14. What are the main parts of an Enterprise JavaBean component architecture?
- Enterprise JavaBean component: This is what's usually thought of as an Enterprise JavaBean. This part of the system is responsible for implementing the business rules associated with your application, while all of the other parts of the system provide supporting functionality.
- Enterprise JavaBean container: EJB components live inside an Enterprise JavaBean container. The container is responsible for providing many of the services associated with Enterprise JavaBeans, in general. These services include transactions, versioning, persistence, and scalability. Many vendors of application servers and transaction processing monitors have already added or are working hard to add EJB container functionality to their products.
- Enterprise JavaBean object: This is the largely invisible part of the EJB architecture. The EJB object is a class that has an identical interface as the EJB component. Its job is to be loaded locally by an application and act as a proxy that communicates to the EJB component (via the EJB container) to actually make things work.
15. Can the Enterprise JavaBeans I create be used with any EJB-compliant application server?
Maybe. Although interoperability is certainly the aim, the current Enterprise JavaBeans specification gives application server developers many choices as to which services they provide and exactly how they're provided. This is potentially problematic for EJB-component developers who must rely on EJB containers (typically application servers) for their livelihood. As a result, using EJB components and application servers interchangeably requires serious testing and a bit of luck today. As the specification evolves, however, many of these issues will be resolved.