FreeKB - Java Programming Understanding beans
Java Programming - Understanding beans

A bean is simply a class that adheres to the following rules.

  • Has getters and setters methods (eg setFoo, getFoo)
  • A public no-argument constructor
  • Implements

For example, lets say you've created a dynamic web application that contains a package named com.sample.main.


And then you've created a class called People in the package.


Add the following to This bean will display the text "John Doe".

package com.sample.main;

// implement
public class MyBean implements {

    // private variables
    private static final long serialVersionUID = -3774654564564563L;
    private String name;

    // constructor
    public MyBean() {
    	name = "Jane Doe";
    public MyBean(String name) { = name;

    // getter
    public String getName() {
        return name;
    // setter
    public void setName(String name) { = name;


The bean can be imported into a JSP page.


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter f9653 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |