Java Bean Example

May 13th, 2011No Comments

what is a java bean?

A Java class  with the following restrictions is called as JAVA BEAN.

1) All the data fields must be private.

2) It must have default constructor.

3) For each data fields “get” and “set” methods must be available.

example bean://employee bean


class employee{

private int id;

private String name;

public Employee(){ } //default constructor

public int getId(){ return id; }

public void setId(int id){ this.id=id; }

public String getName(){ return name; }

public setName(String name){ this.name=name; }

}

}

Advantages of Beans:

1-> Reading of form data becomes easier.

2-> Sharing of bean objects becomes easier.

3-> reusability

VN:F [1.9.10_1130]
Rating: 9.3/10 (6 votes cast)
VN:F [1.9.10_1130]
Rating: +7 (from 7 votes)

Java Bean Example, 9.3 out of 10 based on 6 ratings

About author:

All entries by

Leave a Reply