JAVA BEAN
A JavaBean is a special type of Java class that you can use in several interesting ways to simplify program development. Some beans, such as Swing components, are designed to be visual components that you can use in a GUI editor to quickly build user interfaces. Other beans, known as Enterprise JavaBeans, are designed to run on special EJB servers and can run the data access and business logic for large Web applications.
In this chapter, I look at a more modest type of JavaBean that’s designed to simplify the task of building Java Server Pages. In a nutshell, you can use the simple JavaBeans to build Java Server Pages without writing any Java code in the JSP itself. JavaBeans let you access Java classes by using special HTML-like tags in the JSP page.
Features of Java Beans
A JavaBean is any Java class that conforms to the following rules:
✦ It must have an empty constructor. That is, a constructor that accepts no parameters. If the class doesn’t have any constructors at all, it qualifies because the default constructor has no parameters. But if the class has at least one constructor that accepts one or more parameters, it must also have a constructor that has no parameters to qualify as a JavaBean.
✦ It must have no public instance variables. All the instance variables defined by the class must be either private or protected.
✦ It must provide methods named getProperty and setProperty to get and set the value of any properties the class provides, except for boolean properties that use isProperty to get the property value. The term property isn’t really an official Java term. In a nutshell (or should it be, in a