O'Reilly logo

MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL by James Turner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Bean Basics

A Bean is an encapsulated unit of data with accessor methods to set and get properties, and action methods to do things with the data. As a simple example, a user Bean might have properties such as lastName, firstName, city, state, and zipCode. It might also have action methods such as validateZipCode or saveToDatabase.

The only real requirement for a Bean is that it implements a get and set method of each property that it contains. The methods must start with get or set. That's the basic definition of a Bean.

Let's look at a simple Bean that implements user data in Listing 2.1.

Listing 2.1. User.java
 package com.cartapp.user; public class User { protected String lastName; protected String firstName; public String getLastName() { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required