Bean Internals  «Prev 

Structure of JavaBean

This lesson marks your first exposure into really learning the internals of the JavaBeans technology. The details of JavaBeans are presented using an inside-out approach, meaning that you learn about the inner workings of a Bean and then progress to learning about how a Bean functions externally later in the course.
This approach is beneficial in that it immediately reveals the structural simplicity of JavaBeans. This is not to say that there are not complex issues associated with any type of component software, including JavaBeans. JavaBeans is a very streamlined technology and is easy to comprehend at its core.
The description of the basic structure of a Bean in this lesson will reinforce the simplicity of JavaBeans.

JavaBean Example

The following Java class is used to represent customers in our system. We will name this class Customer. Customer is a simple Java class that defines eight properties:
id, firstName, lastName, street, city, state, zip, and country. 

Properties are attributes that can be accessed via the class�s fields or through public set and get methods. A Java class that follows this pattern is also called a JavaBean:

public class Customer {
 private int id;
 private String firstName;
 private String lastName;
 private String street;
 private String city;
 private String state;
 private String zip;
 private String country;

 public int getId() {
  return id;
 }

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

 public String getFirstName() {
  return firstName;
 }

 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 public String getLastName() {
  return lastName;
 }

 public void setLastName(String lastName) {
  this.lastName = lastName;
 }

 public String getStreet() {
  return street;
 }

 public void setStreet(String street) {
  this.street = street;
 }

 public String getCity() {
  return city;
 }

 public void setCity(String city) {
  this.city = city;
 }

 public String getState() {
  return state;
 }

 public void setState(String state) {
  this.state = state;
 }

 public String getZip() {
  return zip;
 }

 public void setZip(String zip) {
  this.zip = zip;
 }

 public String getCountry() {
  return country;
 }

 public void setCountry(String country) {
  this.country = country;
 }
}