Sunday, 1 February 2015

Java Beans - Java Beans Questions and Answers

51. Write a simple bean program?
Write the SimpleBean code. Put it in a file named, in the directory of your choice. Here's the code:
import java.awt.Color;
import java.beans.XMLDecoder;
import javax.swing.JLabel;

public class SimpleBean extends JLabel
implements Serializable {
public SimpleBean() {
setText( "Hello world!" );
setOpaque( true );
setBackground( Color.RED );
setForeground( Color.YELLOW );
setVerticalAlignment( CENTER );
setHorizontalAlignment( CENTER );

52. 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.

53. 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.

54. 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.

55. 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.

56. 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.

57. What are Java Beans?
Java Beans are usual Java classes which adhere to certain coding conventions:
? Implements interface
? Provides no argument constructor
? Provides getter and setter methods for accessing it's properties.
More Questions & Answers :-
Part1  Part2  Part3  Part4  Part5  Part6

No comments:

Post a Comment