what is Serializable in java?i want desription abt Serializable and how to use?and why we have to use?
Steve Simon Joseph Fernandez
Ranch Hand
Joined: Jul 17, 2005
Posts: 35
posted
0
Hi,
'Serializable' is a marker interface. A marker interface is one that has no methods. By implimenting a marker interface, you're telling the JRE that your class has specific properties. For example, if your class implements Serializable, then the JRE knows that it doesn't have to do anything special to serialize it. (convert an object of your class into a byte stream) Hope this helps.
For permanent storage of object details (Object State) outside the program scope (i.e. store to a file/ pass the object across the network) we implement the class with Serializable marker interface as follows.
Generally, basic data types can be literally stored into any file permanently, when it comes to object state, Java provides an inbuilt way of storing the instance variables of the objects to any stream using Serializable Interface.
Hope this helps.
Regards Roshini
Myra Rose
Ranch Hand
Joined: Jul 27, 2006
Posts: 44
posted
0
I am still not getting the concept of using Serialization in Java.
Can anybody eloborate?
When do u need feel to serialize an object. If I have an employee object and want to store it in database, do I need to serialize employee object?
Ernest Friedman-Hill
author and iconoclast
Marshal
Originally posted by Ritika Agarwal: If I have an employee object and want to store it in database, do I need to serialize employee object?
That would be one way, but not the only way, to do it.
Just one common example: serialization is often used to save and migrate user sessions in a servlet container. Imagine you have a whole server farm with machines A, B, C, and D. Machine A handles a request, and after the request, stores the user session into a file on a shared disk using serialization. Machine C gets the next request from that user, so loads the session and services the request. It's easy, simple, and doesn't require the server to know anything about what's in the session.
"Object-relational mapping". If you have a large number of instances of class X to store, then you can define a database table X with columns that correspond to the fields of X. To store an object, you create a new row in the table, saving each field into the apropriate column. To retrieve an object, you create an empty one, and store the data from one row in the table into its fields.
There exist many software packages that do this automatically -- Hibernate is a very well known one.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.