File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes SERIALIZABLE INTERFACE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "SERIALIZABLE INTERFACE" Watch "SERIALIZABLE INTERFACE" New topic
Author

SERIALIZABLE INTERFACE

thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
Why do we need to implement Serializable interface on Java Beans (getter/setter methods)?
In my application, I am implementing Serializable interface for all java beans. I know that, I am doing it for the persistence. But I neither use ObjectInput/OutputStreams to read and write to file system, hard disk and nor handle any other kind of persistence when system crashes/or when system down.
It is advisable to store all data in one bean and in turn it should store in session object, hence I will have only one session object through out my application .Why is it advisable that object to be implemented by Serializable interface. How data is going to be persisted? I am not writing and persistence logic in my application.
Please answer my question´┐Ż.
Krishnanunni
Greenhorn

Joined: Feb 06, 2002
Posts: 1
U have made a bean class and is used in servlet and jsp page. now a user access that servlet/jsp page and your bean variables have changed to new value.and u are keeping it in session, so that a later time u can retrieve the values from session. but tell me how u are going to store it in session. I mean when u are saying that "storing" in session, u mean that your object should be persistant. isn't it... The web container treats it in that way.
got it......
thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
But you did not answer my question.I know that storing object in session will be persisted through out the user session.
But my question is given below..
Why do we need to implement Serializable interface on Java Beans (getter/setter methods)?
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

Hi thomas,
the web server needs the bean to be serializable
as for it to maintain the session information the beans may be written to a flat file on the server and read again when required.
even if u are not doin any writing\reading to the flat file on ur own the server needs it to handle persistance though this may vary from server to server.
I hope that clears ur doubt.
Devesh H Rao
thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
Even if the object is not implemented by serializable, I am able to store it in session and retrieve back when I required the data from it. I think the session management does not demand for making that object serializable.
I would like to know why does web server use serializable interface when java object being used for getting and setting data from FORM (getter/setter methods)?
Why is it advisable an object to be implemented by serializable(web application)?
Whether to support session management capability of web server or to support crisis management, I mean in case of system crash/server down etc..
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
As I understand it, it is up to the servlet container designer to decide whether or not to serialize sessions out to disk or database when it starts to run out of memory - the alternative being to just discard the session before the normal timeout.
Your session with a non-serializable object may work just fine with a given server and usage load but fail when the load gets higher.
Serializing out to disk or database is a simple way to make your application more able to survive system crashes, etc. - it really is pretty fast. Also, of course, serializing objects is basic to functioning in the J2EE environment.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SERIALIZABLE INTERFACE