Design Patterns for Properties in a Java Bean

By: Sam Chen Emailed: 1608 times Printed: 2076 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

A property is a subset of a Bean's state. The values assigned to the properties determine the behavior and appearance of that component. This section discusses three types of properties: simple, Boolean, and indexed.

Simple Properties

A simple property has a single value. It can be identified by the following design patterns, where N is the name of the property and T is its type.

public T getN( );
public void setN(T arg);

A read/write property has both of these methods to access its values. A read-only property has only a get method. A write-only property has only a set method. The following listing shows a class that has three read/write simple properties:

public class Box {
 
private double depth, height, width;
public double getDepth( ) {
return depth;
}
public void setDepth(double d) {
depth = d;
}
public double getHeight( ) {
return height;
}
public void setHeight(double h) {
height = h;
}
public double getWidth( ) {
return width;
}
public void setWidth(double w) {
width = w;
}
}

Boolean Properties

A Boolean property has a value of true or false. It can be identified by the following design patterns, where N is the name of the property:

public boolean isN( );
public boolean getN( );
public void setN(boolean value);

Either the first or second pattern can be used to retrieve the value of a Boolean property. However, if a class has both of these methods, the first pattern is used. The following listing shows a class that has one Boolean property:

public class Line {
private boolean dotted = false;
public boolean isDotted( ) {
return dotted;
}
public void setDotted(boolean dotted) {
this.dotted = dotted;
}
}

Indexed Properties

An indexed property consists of multiple values. It can be identified by the following design patterns, where N is the name of the property and T is its type:

public T getN(int index);
public void setN(int index, T value);
public T[ ] getN( );
public void setN(T values[ ]);

The following listing shows a class that has one read/write indexed property:

public class PieChart {
private double data[ ];
public double getData(int index) {
return data[index];
}
public void setData(int index, double value) {
data[index] = value;
}
public double[ ] getData( ) {
return data;
}
public void setData(double[ ] values) {
data = new double[values.length];
System.arraycopy(values, 0, data, 0, values.length);
}
}


Java Beans Home | All Java Beans Tutorials | Latest Java Beans Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sam Chen
Extract filename from full path using perl
Encrypting Passwords in Tomcat using Servlets
malloc, calloc - Storage Management - in C
Character Pointers and Functions in C
Declarations in C
strcpy() and strncpy() sample program in C++
Sample program to draw a rectangle in J2ME
Design Patterns for Properties in a Java Bean
PushbackInputStream example program in Java
FileInputStream - sample program in Java

More Tutorials in Java Beans
Creating a JavaBean to Connect with Google API
Spring Vs EJB ( A feature comparison)
What is EJB server and what are EJB Components?
JavaBeans Basic Concepts
JavaBeans vs. Custom Tags
Java Beans and the Expression Language
A sample that shows Java Beans, Servlets and JSP working together
Advantages of Java Beans
Design Patterns for Properties in a Java Bean
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
ADVANTAGES OF EJB
Steps to develop EJB Environment
EJB is a server side component:
Entity Bean
History Of Java

More Latest News
Most Viewed Articles (in Java Beans )
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Advantages of Java Beans
A sample that shows Java Beans, Servlets and JSP working together
ADVANTAGES OF EJB
History Of Java
Design Patterns for Properties in a Java Bean
JavaBeans Basic Concepts
Spring Vs EJB ( A feature comparison)
Reusable component
Steps to develop EJB Environment
EJB is a server side component:
Entity Bean
Java Beans and the Expression Language
JavaBeans vs. Custom Tags
What is EJB server and what are EJB Components?
Most Emailed Articles (in Java Beans)
Entity Bean
ADVANTAGES OF EJB
EJB is a server side component:
Steps to develop EJB Environment
JavaBeans Basic Concepts
What is EJB server and what are EJB Components?
History Of Java
JavaBeans vs. Custom Tags
Spring Vs EJB ( A feature comparison)
Reusable component
Advantages of Java Beans
Design Patterns for Properties in a Java Bean
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
A sample that shows Java Beans, Servlets and JSP working together
Creating a JavaBean to Connect with Google API