I guess you are just confused because the term POJO is often used interchangeably with JavaBeans. As the name suggests a POJO in general is a plain old Java object for example in contrast to Enterprise JavaBeans in EJB version 2.x which had to implement or inherit from cumbersome API classes and interfaces.
It's arguable if a POJO is the same as a JavaBean but at least the rules to create JavaBeans is where the Serializable interface comes from. Please take a look at the API. Another characteristic of JavaBeans you will be more familiar with are the well-known getters and setters for class members
Joined: Dec 12, 2006
Thanks of the quick reply... Actually my question is not in terms of EJB 2.0.
Assume that i am not using any frame work.
I have a simple web application which uses Servlet as controller. and jsp as view
And i have Class Employee which is POJO which has getter setter default no argument constructor and implements serializable interface.
The job of servlet is to create one instance of Employee POJO. set the request parameter values got from JSP into Employee POJO using employee's setter method. and pass the pojo to some other method for further processing.
in this case what is the use of implementing serializable interface in Employee class.
Or implementing serializable has nothing to do with POJO ??/
The thing with EJBs was just to explain what would NOT be a POJO
Or implementing serializable has nothing to do with POJO ??
It has to do with POJOs as soon as you use the term POJO as a synonym for JavaBean. Classes which follow the JavaBeans conventions should implement Serializable because this marks them as being transferable over network or and Serializable objects can be "serialized" to a persistent storage.
If for you a JavaBean is exactly the same as a POJO then of course a POJO should implement Serializable. If a POJO for you is not exactly the same as a JavaBean then Serializable has nothing to do with POJOs. For my understanding a POJO is not the same as a JavaBean but instead an object or class which does not implement any special interfaces and does not inherit from any special API classes.
But don't worry to much about this naming issue. You will surely see many different interpretations on the web regarding the term POJO. Originally it was coined and used by Martin Fowler to differentiate between classes which contain just your application logic and the said classes (like EJBs) which had to implement complicated interfaces or something like this.
As David Newton said, "So its objects can be serialized..." (stored and retrieved).
"Serializable" is called a marker interface because it has no fields or methods; it's
entirely empty. Since the serialization process can be tricky, as there are rules
and the programmer has a lot of flexibility, it often requires quite a bit of custom
code. By implementing Serializable, the programmer is declaring that this work
has been done and the needed behaviors are in place.
BEE MBA PMP SCJP-6
Joined: Dec 12, 2006
Thanks a lot all of you for detail explanation...
My understanding is now very clear about POJO and implementing serializalbe in POJO.