Java Bean

JavaBeans are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that the bean can be passed around rather than the individual objects.The specification by Sun Microsystems defines them as "reusable software components that can be manipulated visually in a builder tool".


       public class PersonBean implements 
        private String name;
        private boolean deceased;
        // No-arg constructor (takes no arguments).
        public PersonBean() {


       // Property "name" (note capitalization) 
       public String getName() {

       public void setName(String name) {
  = name;


       // Property "deceased"
       // Different syntax for a boolean field 
          (is vs. get)

       public boolean isDeceased() {
           return this.deceased;

       public void setDeceased(boolean deceased) {
         this.deceased = deceased;



    public class TestPersonBean {
    public static void main(String[] args) {

    PersonBean person = new PersonBean();

    // Output: "Bob [alive]"
        ? " [deceased]" : " [alive]");

Post a Comment

Popular posts from this blog

Secure Spring Boot REST API using Basic Authentication

Integrating Swagger with Spring Boot REST API

Building a RESTFul Service using Spring Boot