answersLogoWhite

0

What does the serialization interface do?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

Imagine you want to save the state of one or more objects. If Java didn't have serialization, you'd have to use one of the I/O classes to write out the state of the instance variables of all the objects you want to save. The worst part would be trying to reconstruct new objects that were virtually identical to the objects you were trying to save. You'd need your own protocol for the way in which you wrote and restored the state of each object, or you could end up setting variables with the wrong values. For example, imagine you stored an object that has instance variables for height and weight. At the time you save the state of the object, you could write out the height and weight as two ints in a file, but the order in which you write them is crucial. It would be all too easy to re-create the object but mix up the height and weight values-using the saved height as the value for the new object's weight and vice versa.

The purpose of Serialization is to help us achieve whatever complicated scenario we just witnessed in an easier manner.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What does the serialization interface do?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is serializable class in JAVA?

The serializable interface is used to perform the serialization action. Serialization is the process by which the contents of an object are written to any form of storage - say a flat file. This data stored in the flat file can be de-serialized at any time to create the object. Ex: public class Test implements Serializable { … //lots of code }


How is Java persistence done?

Java persistence is implemented using serialization. Serialization is a technique in java using which the contents of a java object (A class instance) can be written into a flat file. This value can be unserialized or deserialized at a later point of time to create the object. Any class that implements the Serializable interface can be serialized.


What is Externalizable interface?

The Externizable interface extends the serializable interface.When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject()two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process. The two methods to be implemented are :void readExternal(ObjectInput)void writeExternal(ObjectOutput)


What is deserialization in java?

De-serialization is the opposite process of serialization. This is the process where we convert data that has already been written out onto a stream as part of serialization into Java objects.


What is serialization in Java?

Serialization is the ability to easily store the state of an Object in memory onto some long-term medium (on a hard drive, for example). Basically, the Serializable interface allows us to tell Java to turn our Object into a byte-stream. The Object could be a document that the user is working on, or a more complex data class which needs the ability to be saved to the hard drive. Using the Serializable interface (and related I/O methods), Java will do most of the work for us.


What is serialization in NET What are the ways to control serialization?

SerializationSerialization is a process of taking an object and converting into a form so that it can be transported across the network or can be persisted in the storage location. This storage location can be physical file, database or ASP.NET Cache. The form contains the state of the object so that by this format, we can construct the same object a later point in time, which is called Deserialization. There are three formats of serializationBinary Serialization : Light and compact used in RemotingSOAP Serialization : interoperable use SOAP and used in web ServicesXML Serialization : Custom SerializationXML SerializationFor XML serialization, you need to use the attributes and specify them for each and every public member that you need. But since it is limited that it can serialize only public members, Serization done by it is called custom serialization. It is also known as Shallow SerializationSOAP and Binary SerializationXML serializes only public members of the class. You use SOAP or Binary serialization when you need to transport data across the network. SOAP sends it using HTTP Protocol which makes it most interoperable while Binary serialization is known for its light and compact nature. Web Services uses the SOAP Serialization and Remoting uses the Binary Serialization. Infact Serialization is always necessary when you need the object to transfer across a network. Advantage of using the SOAP or Binary serialization is that you can serialize the entire object and all those object that are being refrenced by it. This is why it is also called Deep Serialization. If you want any class to serialize through any of these methods then you should use [Serializable] attribute on that class and then you can use the SoapFormater class or BinaryFormatter class to do the serialization. These classes have Serialize and DeSerialize method. If you will not use SerializableAttribute for the class, then it will raise the exception.Though this is the easiest way but at time you need the way so that you can decide what fields to serialize and how the serialization actually occurs. You can implement the ISerializable interface in the class. You need two things for thatConstructor that is overridden and can handle the Deserialization processGetObject method that tracks about which data is serialized.A small example below illustrate this all.public class Employee :ISerializable{private int emp_no;private string name;protected TestData(SerializationInfo info,StreamingContext context){this.emp_no = info.GetInt32("emp_no");this.name = info.GetString("name");}void ISerializable.GetObjectData(SerializationInfo info,StreamingContext context){info.AddValue("emp_no", this.emp_no);info.AddValue("name", this.name);}}}


What is meaning Serialize in java?

Primary purpose of java serialization is to write an object into a stream, so that it can be transported through a network and that object can be rebuilt again. When there are two different parties involved, you need a protocol to rebuild the exact same object again. Java serialization API just provides you that. Other ways you can leverage the feature of serialization is, you can use it to perform a deep copy. Why I used 'primary purpose' in the above definition is, sometimes people use java serialization as a replacement for database. Just a placeholder where you can persist an object across sessions. This is not the primary purpose of java serialization. Sometimes, people say that java serialization is used for storing (to preserve the state) an object and retrieving it. They use it synonymously with database. This is a wrong perception for serialization.


What is exteranalizable in java?

Externalizable interface is a subclass of Serializable. Java provides Externalizable interface so as to give you more control over what is being serialized and what is not. Using this interface, you can Serialize only the fields of the class you want serialize and ignore the rest. This interface defines 2 methods: readExternal() and writeExternal() and you have to implement these methods in the class that will be serialized. In these methods you'll have to write code that reads/writes only the values of the attributes you are interested in. Programs that perform serialization and deserialization have to write and read these attributes in the same sequence


Is surbrec Nora the second out in Engligh?

No it's currently in serialization


What is the default serialization used for ASPNet Ajax calls?

JavaScript Object Notation


What is the process of writing the state of an object to a byte stream called?

This is called serialization.


What is use of serialization in java?

Serialization will turn a Java Object into a text string (representing it's contents) which can be persisted to a storage device or sent over a network. There is an opposite process of turning the text string representation back into an instanciated Object.