Java Beans Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What are Java Beans?
Java Beans are usual Java classes which adhere to certain coding conventions:
► Implements java.io.Serializable interface
► Provides no argument constructor
► Provides getter and setter methods for accessing it's properties.
Ques 2. Why do I get a NullPointerException when loading a JAR file into the BeanBox?
Usually this is because of a mistake in the JAR file being loaded. In the meantime, typical errors include:
► The MANIFEST file uses classes using the wrong file separator ("/" should be used in all platforms).
► The MANIFEST file refers to classes in a package but the actual .class files are not really in that package.
Ques 3. What is bean persistance property?
A bean has the property of persistence when its properties, fields, and state information are saved to and retrieved from storage. Component models provide a mechanism for persistence that enables the state of components to be stored in a non-volatile place for later retrieval.
Ques 4. What are externizable interface?
Use the Externalizable interface when you need complete control over your bean's serialization (for example, when writing and reading a specific file format).
To use the Externalizable interface you need to implement two methods: readExternal and writeExternal. Classes that implement Externalizable must have a no-argument constructor.
Ques 5. What are the purpose of introspection?
A growing number of Java object repository sites exist on the Internet in answer to the demand for centralized deployment of applets, classes, and source code in general. Any developer who has spent time hunting through these sites for licensable Java code to incorporate into a program has undoubtedly struggled with issues of how to quickly and cleanly integrate code from one particular source into an application.
The way in which introspection is implemented provides great advantages, including:
► Portability - Everything is done in the Java platform, so you can write components once, reuse them everywhere. There are no extra specification files that need to be maintained independently from your component code. There are no platform-specific issues to contend with. Your component is not tied to one component model or one proprietary platform. You get all the advantages of the evolving Java APIs, while maintaining the portability of your components.
► Reuse - By following the JavaBeans design conventions, implementing the appropriate interfaces, and extending the appropriate classes, you provide yourcomponent with reuse potential that possibly exceeds your expectations.
Ques 6. What is property editor in java beans?
A property editor is a tool for customizing a particular property type. Property editors are activated in the Properties window. This window determines a property's type, searches for a relevant property editor, and displays the property's current value in a relevant way.
Ques 7. Write a simple bean program?
Write the SimpleBean code. Put it in a file named SimpleBean.java, in the directory of your choice. Here's the code:
import java.awt.Color;
import java.beans.XMLDecoder;
import javax.swing.JLabel;
import java.io.Serializable;
public class SimpleBean extends JLabel
implements Serializable {
public SimpleBean() {
setText( "Hello world!" );
setOpaque( true );
setBackground( Color.RED );
setForeground( Color.YELLOW );
setVerticalAlignment( CENTER );
setHorizontalAlignment( CENTER );
}
}
Ques 8. Difference between java bean and bean?
A Java Bean is a software component written in the Java programming language that conforms to the JavaBeans component specification. The JavaBeans APIs became part of the "core" Java APIs as of the 1.1 release of the JDK.
The JavaBeans specification defines a Java-based software component model that adds a number of features to the Java programming language. Some of these features include:
► introspection
► customization
► events
► properties
► persistence
Enterprise JavaBeans (EJBs) are Java-based software components that are built to comply with Java's EJB specification and run inside of an EJB container supplied by a J2EE provider. An EJB container provides distributed application functionality such as transaction support, persistence and lifecycle management for the EJBs.
Ques 9. What is a Bean? Why is not a Bean an Applet?
JavaBeans components, or Beans, are reusable software components that can be manipulated visually in a builder tool. Beans can be combined to create traditional applications, or their smaller web-oriented brethren, applets. In addition, applets can be designed to work as reusable Beans.
Individual Beans will function quite differently, but typical unifying features that distinguish a Bean are:
► Introspection: enables a builder tool to analyze how a Bean works
► Customization: enables a developer to use an app builder tool to customize the appearance and behavior of a Bean
► Events: enables Beans to communicate and connect together
► Properties: enable developers to customize and program with Beans
► Persistence: enables developers to customize Beans in an app builder, and then retrieve those Beans, with customized features intact, for future use.
Ques 10. Why are component architectures useful?
Developers are turning to creating components rather than monolithic applications to free themselves from slow, expensive application development, and to build up a portable, reusable code base. This enables developers to quickly attack new market opportunities, new joint development opportunities, and new ways to sell smaller packages of software.
Ques 11. Is JavaBeans a complete component architecture?
JavaBeans is a complete component model. It supports the standard component architecture features of properties, events, methods, and persistence. In addition, JavaBeans provides support for introspection (to allow automatic analysis of a JavaBeanscomponent) and customization (to make it easy to configure a JavaBeans component).
Ques 12. Why a component architecture for the Java platform?
JavaBeans brings the extraordinary power of the Java platform to component development, offering the ideal environment for a developer who wants to extend the concept of reusable component development beyond one platform and one architecture to embrace every platform and every architecture in the industry.
Ques 13. What kind of industry support exists for JavaBeans?
A coalition of industry leaders in component development worked with JavaSoft to create the JavaBeans specification, which was released to the Internet for public comments on September 4, 1996. The "frozen" JavaBeans specification combines the work of Apple, Borland, IBM, JustSystem, Microsoft, Netscape, Rogue Wave, SunSoft and Symantec and many, many others... We're very pleased to see the tools community swiftly embracing JavaBeans by announcing support for JavaBeans in their visual application builder tools.
Ques 14. Are there JavaBeans components available that I can buy today?
Yes. A large number of companies, both large and small, have announced their plans to deliver JavaBeans-based products.
Ques 15. Why nobody at Sun wants to read the messages sent to java-beans@java.sun.com?
Because of the fact, that 99% of all messages is spam. It is recommended to post on JavaBeans forum, which is inspected by Sun engineers on a regular basis.
Ques 16. What is the relationship between Sun s JFCs and JavaBeans?
The JFC (Java Foundation Classes) is based upon the AWT (Abstract Windowing Toolkit), which has been part of the Java platform from the beginning. JFC effectively adds a richer set of visual elements for building JavaBeans components and applications. See the JFC web site for more information.
Ques 17. Why do I get a duplicate name error when loading a JAR file?
The most common reason for a "java.lang.ClassFormatError: Duplicate name" error is that a .class file in the JAR contains a class whose class name is different from the expected name. So for example if you have a file called "a/B.class" and it contains a class called "B" or "a.X" instead of the class "a.B" then you will get this error.
Themost common causes for this problem are either forgetting to include a "package a;" statement or having a "package" statement with the wrong name.
Ques 18. What are the security implications for downloading Beans over the Internet?
JavaBeans does not add any security features to the Java platform. Rather, JavaBeans components have full access to the broad range of security features that are part of the Java platform. JavaBeans components can be used to build a range of different kinds of solutions from full-fledged Java desktop applications to web-based Applets.
Ques 19. When will JavaBeans be supported on the [fill in the blank] platform/operating system?
The complete set of JavaBeans APIs are core to Java 2, hence any platform that is fully compatible with Java 2 implicitly supports JavaBeans. Thus, JavaBeans support will be available as soon as this platform/operating system vendor supports Java 2.
Ques 20. What is entity reference?
A reference to an entity that is substituted for the reference when the XML document is parsed. It can reference a predefined entity such as < or reference one that is defined in the DTD. In the XML data, the reference could be to an entity that is defined in the local subset of the DTD or to an external XML file (an external entity). The DTD can also carve out a segment of DTD specifications and give it a name so that it can be reused (included) at multiple points in the DTD by defining a parameter entity.
Ques 21. What is an entity?
A distinct, individual item that can be included in an XML document by referencing it. Such an entity reference can name an entity as small as a character (for example, <, which references the less-than symbol or left angle bracket, <). An entity reference can also reference an entire document, an external entity, or a collection of DTD definitions.
Ques 22. What is enterprise bean provider?
An application developer who produces enterprise bean classes, remote and Interview Questions - Home interfaces, and deployment descriptor files, and packages them in an EJB JAR file.
Ques 23. What is Enterprise JavaBeans Query Language?
Defines the queries for the finder and select methods of an entity bean having container-managed persistence. A subset of SQL92, EJB QL has extensions that allow navigation over the relationships defined in an entity bean's abstract schema.
Ques 24. What is Enterprise JavaBeans?
A component architecture for the development and deployment of object-oriented, distributed, enterprise-level applications. Applications written using the Enterprise JavaBeans architecture are scalable, transactional, and secure.
Ques 25. What is enterprise information system?
The applications that constitute an enterprise's existing system for handling companywide information. These applications provide an information infrastructure for an enterprise. An enterpriseinformation system offers a well-defined set of services to its clients. These services are exposed to clients as local or remote interfaces or both. Examples of enterprise information systems include enterprise resource planning systems, mainframe transaction processing systems, and legacy database systems.
Ques 26. What is EJB server?
Software that provides services to an EJB container. For example, an EJB container typically relies on a transaction manager that is part of the EJBserver to perform the two-phase commit across all the participating resource managers. The J2EE architecture assumes that an EJB container is hosted by an EJBserver from the same vendor, so it does not specify the contract between these two entities. An EJB server can host one or more EJB containers.
Ques 27. What is entity bean?
An enterprise bean that represents persistent data maintained in a database. An entity bean can manage its own persistence or can delegate this function to its container. An entity bean is identified by a primary key. If the container in which an entity bean is hosted crashes, the entity bean, its primary key, and any remote references survive the crash.
Ques 28. What is EJB object?
An object whose class implements the enterprise bean's remote interface. A client never references an enterprise bean instance directly. A client always references an EJB object. The class of an EJB object is generated by a container's deployment tools.
Ques 29. What is EJB Home object?
An object that provides the life-cycle operations (create, remove, find) for an enterprise bean. The class for the EJB Home object is generated by the container's deployment tools. The EJB Home object implements the enterprise bean's Home interface. The client references an EJB Home object to perform life-cycle operations on an EJB object. The client uses JNDI to locate an EJB Home object.
Ques 30. What is EJB context?
A vendor that supplies an EJB container. An object that allows an enterprise bean to invoke services provided by the container and to obtain the information about the caller of a client-invoked method.
Ques 31. What is EJB container?
A container that implements the EJB component contract of the J2EE architecture. This contract specifies a runtime environment for enterprise beans that includes security, concurrency, life-cycle management, transactions, deployment, naming, and other services. An EJB container is provided by an EJB or J2EE server.
Ques 32. What is bean customization?
Customization provides a means for modifying the appearance and behavior of a bean within an application builder so it meets your specific needs. There are several levels of customization available for a bean developer to allow other developers to get maximum benefit from a bean?s potential functionality.
1.By using a property editor. Each bean property has its own property editor. The NetBeans GUI Builder usually displays a bean's property editors in the Properties window. The property editor that is associated with a particular property type edits that property type.
2. By using customizers. Customizers give you complete GUI control over bean customization. Customizers are used where property editors are not practical or applicable. Unlike a property editor, which is associated with a property, a customizer is associated with a bean.
Ques 33. What are introspection API in java beans?
The JavaBeans API architecture supplies a set of classes and interfaces to provide introspection. The BeanInfo (in the API reference documentation) interface of the java.beans package defines a set of methods that allow bean implementors to provide explicit information about their beans. By specifying BeanInfo for a bean component, a developer can hide methods, specify an icon for the toolbox, provide descriptive names for properties, define which properties are bound properties, and much more. The getBeanInfo(beanName) (in the API reference documentation) of the Introspector (in the API reference documentation) class can be used by builder tools and other automated environments to provide detailed information about a bean. The getBeanInfo method relies on the naming conventions for the bean's properties, events, and methods. A call to getBeanInfo results in the introspection process analyzing the bean?s classes and superclasses.
Ques 34. What is introspection properties in java beans?
Introspection is the automatic process of analyzing a bean's design patterns to reveal the bean's properties, events, and methods.
Ques 35. How to control serialization in java beans?
Three ways to control serilization in java beans:
1.Automatic serialization, implemented by the Serializable interface. The Java serialization software serializes the entire object, except transient and static fields.
2.Customized serialization. Selectively exclude fields you do not want serialized by marking with the transient (or static) modifier.
3.Customized file format, implemented by the Externalizable interface and its two methods. Beans are written in a specific file format.
Ques 36. What is the serializable class in java beans?
Any class is serializable as long as that class or a parent class implements the java.io.Serializable interface. Examples of serializable classes include Component, String, Date, Vector, and Hashtable.
Ques 37. How to create bound property in bean application?
To create the title property as a bound property for the MyBean component in the NetBeans GUI Builder, perform the following sequence of operations:
► Right-click the Bean Patterns node in the MyBean class hierarchy.
► Select Add|Property from the pop-up menu.
► Fill the New Property Pattern form as shown on the following figure and click OK.
Ques 38. What is Glasgow?
Glasgow - the code name for add-ins to the JavaBeans specification. It contains following specifications:
► The Extensible Runtime Containment and Services Protocol
► The Drag and Drop Subsystem for the Java Foundation Classes
► The JavaBeans Activation Framework
Ques 39. How does the InfoBus relate to JavaBeans?
The InfoBus specification extends JavaBeans by providing a set of enhanced interfaces to share and exchange dynamic data.
Ques 40. Will the general public have access to the InfoBus API s?
Yes, under the usual terms of the JDK license. The specification and technology preview are available in our products archive.
Ques 41. Is the InfoBus client side only?
Yes. InfoBus is typically used to communicate among Beans at the client, and it can also be useful for sharing information among components at a single server site. The initial version of InfoBus is not distributed, and is therefore not intended for transmission of data between clients and servers.
A variety of Java communication services, including JDBC, CORBA, and RMI can be used by InfoBus components for access to distributed data. For example, the ESuite Data Access component is a Bean that connects any JDBC compliant data source to the InfoBus. Once the data is on the bus, it can easily be imported by any InfoBus Data Consumer, such as a spreadsheet, chartingcomponent, word processor or data analysis tool.
Ques 42. Difference between java Beans and Enterprise Java Beans?
► JavaBeans may be visible or nonvisible at runtime.For
example, the visual GUI component may be a button,list
box,graphic or a chart.
An EJB is a nonvisual ,remote object.
► JavaBeans are intended to be local to a single process
and are primarly intended to run on the client side.Although
one can develop server-side JavaBeans,it is far easier to
develop them using the EJB specification instead.
EJB's are remotely executable components or business
objects that can be deployed only on the server.
► JavaBeans is a component technology to create generic
Java components that can be composed together into applets
and applications.
Even though EJB is a component technology,it neither
builds upon nor extends the original JavaBean specification.
► JavaBeans have an external interface called the properties
interface, which allows a builder tool to interpret the
functionality of the bean.
EJBs have a dployement descriptor that describes its
functionality to an external builder tool or IDE
► JavaBeans may have BeanInfo classes,property editors or
customizers
Ques 43. What is the relation between the InfoBus and RMI?
The InfoBus architecture addresses Beans talking to one in a single JVM not across multiple JVMs; while RMI (Remote Method Invocation) is intended for communication across JVMs (different Java Virtual Machines across the network). As for IIOP, one can envision a JavaBeans component that uses RMI to talk to something on another JVM and then publishes the data on the InfoBus.
Additionally, RMI could be used to allow components in different security classes to communicate within the same JVM.
Ques 44. Why is the JavaBeans Bridge for ActiveX only available on Windows/X86?
Sun's JavaBeans Bridge for ActiveX is platform specific due to the platform specific nature of ActiveX. Currently, ActiveX is essentially a Window/X86 platform specific component architecture.
If Microsoft delivers ActiveX libraries and ActiveX applications on other platforms, Sun will evaluate customer demand and respond accordingly.
Ques 45. Who is developing the JavaBeans Migration Assistant to ActiveX?
IBM and Taligent, its object oriented technology subsidiary, with support from JavaSoft, are developing a set of conversion conventions, a porting guide and tool that will allow developers to easily convert their Windows ActiveX components into JavaBeans.
Ques 46. What are/is Enterprise JavaBeans?
Enterprise JavaBeans (EJB) is an API specification for building scalable, distributed, component-based, multi-tier applications. It leverages and extends the JavaBeans component model to provide a rich object-oriented transactional environment for developers building enterprise applications.
Enterprise JavaBeans (EJB) technology is the basis of Java 2 Platform, Enterprise Edition (J2EE). EJB technology provides the scalable architecture for executing business logic in a distributed computing environment. J2EE makes the life of an enterprise developer easier by combining the EJB component architecture with other enterprise technologies to solutions on the Java platform for seamless development and deployment of server side applications.
Ques 47. What are the properties of java beans?
The JavaBeans specification defines the following types of bean properties:
► Simple: A bean property with a single value whose changes are independent of changes in any other property.
► Indexed: A bean property that supports a range of values instead of a single value.
► Bound: A bean property for which a change to the property results in a notification being sent to some other bean.
► Constrained: A bean property for which a change to the property results in validation by another bean. The other bean may reject the change if it is not appropriate.
Bean properties can also be classified as follows:
► Writable: A bean property that can be changed:
► ► Standard
► ► Expert
► ► Preferred
► Read Only: A bean property that cannot be changed.
► Hidden: A bean property that can be changed. However, these properties are not disclosed with the BeanInfo class
Ques 48. What is the InfoBus?
The InfoBus is a compact Java API which allows cooperating applets or Beans, on a Web page or in any other Java application, to communicate data to one another. The InfoBus architecture enables Beans to be categorized as "data providers" and "data consumers". Data providers are Beans whose primary function is to access data from their native store, such as a DBMS, spreadsheet, flat file, Lotus Notes database etc., and to offer data onto the InfoBus.
Data consumers retrieve data from the bus, for analysis or visual display. This segregation of provider from consumer is extremely powerful in that it enables applications to be independent of their data; for example, a charting Bean need not understand SQL or JDBC in order to access DBMS data.
Of course, a Bean can be both a consumer and provider: for example a spreadsheet may accept data from a DBMS and provide data to a chart Bean.
Ques 49. Does the InfoBus compete with JavaBeans?
On the contrary, InfoBus extends the power of JavaBeans to a new range of more dynamic applications. InfoBus is fully compatible with JavaBeans, and Lotus enthusiastically supports JavaBeans as the component standard for Java. Wherever possible, InfoBus uses the existing mechanisms of JavaBeans.
Ques 50. Is InfoBus easy to use?
Using InfoBus aware components, such as the ESuite components from Lotus, users can easily construct powerful data driven applications. No programming or scripting is required: simple parameters are used to establish connections to databases and to select data for processing. For developers creating InfoBus components, InfoBus offers a straightforward API compatible in style with other features of JavaBeans.
Ques 51. JavaBeans has mechanisms like bound properties for data transfer between components. Why is the InfoBus necessary?
JavaBeans mechanisms, such as bound properties, are very useful in cases where the type of data to be communicated can be hard-coded into the source and target components. The InfoBus adds additional features required for more dynamic data interchange. These can be cases where communication is driven by the content of the data and where the nature of the data to be exchanged is determined at runtime.
Ques 52. Can both Java applets and JavaBeans components use the InfoBus?
Yes.
Ques 53. Can JavaBeans use DCOM as its network model?
JavaBeans works with any network model (i.e., to communicate between components across the network), including CORBA, DCOM, etc. JavaBeans integrates well with CORBA IDL, which is an excellent solution for customers in a heterogeneous distributed computing environment with platform independent components. However, we recommend RMI for Java to Java inter-object communication.
Ques 54. Why would a developer need the JavaBeans Migration Assistant for ActiveX?
Many of the capabilities that are so exciting to JavaBeans developers are not available on ActiveX, or are incomplete. There is, therefore, a need for a set of conversion conventions and tools designed to convert desktop ActiveX components into JavaBeans components. The resulting Beans will be usable in both in new network savvy e-business applications as well as traditional desktop applications, includingActiveX containers. Developers and customers benefit from the advantages offered by JavaBeans by simply leveraging their current investments in ActiveX.
Ques 55. How and when will the JavaBeans Migration Assistant to ActiveX be available?
IBM plans to ship the JavaBeans Migration Assistant for ActiveX in Taligent's Visual Age, WebRunner Toolkit, and Visual Age for Java development tools. This will allow developers to utilize a common component model that may be leveraged by a wide range of tools, including the IBM Visual Age for Java family.
Ques 56. How to implement a bound property in your bean application?
To implement a bound property in the application, follow these steps:
► Import the java.beans package. This gives you access to the PropertyChangeSupport class.
► Instantiate a PropertyChangeSupport object. This object maintains the property change listener list and fires property change events. You can also make your class a PropertyChangeSupport subclass.
► Implement methods to maintain the property change listener list. Since a PropertyChangeSupport subclass implements these methods, you merely wrap calls to the property-change support object's methods.
► Modify a property's set method to fire a property change event when the property is changed.
Ques 57. What is the relationship between Enterprise JavaBeans and JavaBeans?
Enterprise JavaBeans extends the JavaBeans component model to handle the needs of transactional business applications.
JavaBeans is a component model for visual construction of reusable components for the Java platform. Enterprise JavaBeans extends JavaBeans to middle-tier/server side business applications. The extensions that Enterprise JavaBeans adds to JavaBeans include support for transactions, state management, and deployment time attributes.
Although applications deploying the Enterprise JavaBeans architecture are independent from the underlying communication protocol, the Enterprise JavaBeans architecture specifies how communication among components maps into the underlying communication protocols, such as CORBA/IIOP.
Most helpful rated by users:
- What are Java Beans?
- Why do I get a NullPointerException when loading a JAR file into the BeanBox?
- What is bean persistance property?
- What are externizable interface?
- What are the purpose of introspection?