Programming Difference Between POJO and Bean

I have the following two classes. Can I say that the first class is POJO and the second is like a Bean class?

1) the POJO class, because it has only the getter and setter method, and all members are declared private

public class POJO { private int id; private String name; public int getId() { return id; } public String getName() { return name; } public void setId() { this.id = id; } public void setName() { this.name = name; } } 

2) Bean class - all member variables are private, have getters and setters, and implements the Serializable interface

 public class Bean implements java.io.Serializable { private String name; private Integer age; public String getName() { return this.name; } public void setName(String name) { this.name = name; } public Integer getAge() { return this.age; } public void setAge(Integer age) { this.age = age; } } 

It also has a no-arg constructor.

+3
java javabeans pojo
source share
2 answers

Only the difference bean can be serialized.

From Java docs - http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html

The serializability of the class is activated by the class that implements the java.io.Serializable interface. Classes that do not implement this interface will not have their serialized or deserialized state. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of serialization.

+9
source share

the JavaBean class must implement either Serializable or Externalizable, must have a no-arg constructor, all JavaBean properties must have a public setter and getter method (if necessary) all JavaBean instance variables must be private

+2
source share

All Articles