Reputation: 47
class Sample implements Serializable
{
// code
}
Now this Sample class is called as POJO..?
Upvotes: 0
Views: 649
Reputation: 3950
In computing based on the Java Platform, JavaBeans are classes that encapsulate many objects into a single object (the bean). They are serializable, have a zero-argument constructor, and allow access to properties using getter and setter methods They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a 0-argument constructor, and allows access to properties using getter and setter methods. A JavaBean is just a standard
All properties private (use getters/setters)
A public no-argument constructor
Implements Serializable.
POJO stands for Plain Old Java Object, and would be used to describe the same things as a "Normal Class" whereas a JavaBean follows a set of rules. Most commonly Beans use getters and setters to protect their member variables, which are typically set to private and have a no-argument public constructor.Hence a pojo which has getters and setter ,no arg constructor and implements serialisable is basically a javabean which can have its states saved and retreived from a file.
Upvotes: 0
Reputation: 847
No, according quoting wikipedia a plain old java object should not: Ideally speaking, a POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification; i.e. a POJO should not have extend prespecified classes, as in
public class Foo extends javax.servlet.http.HttpServlet { ...
Implement prespecified interfaces, as in
public class Bar implements javax.ejb.EntityBean { ...
Contain prespecified annotations, as in
@javax.persistence.Entity public class Baz { ...
See https://en.wikipedia.org/wiki/Plain_old_Java_object for further details.
Upvotes: 2