PREVIOUS
Serialization in JavaSerialization in java is a mechanism of writing the state of an object into a byte stream.It is mainly used in Hibernate, RMI, JPA, EJB, JMS technologies. The reverse operation of serialization is called deserialization. The String class and all the wrapper classes implementsjava.io.Serializable interface by default. Advantage of Java SerializationIt is mainly used to travel object's state on the network (known as marshaling).java.io.Serializable interfaceSerializable is a marker interface (has no body). It is just used to "mark" java classes which support a certain capability.It must be implemented by the class whose object you want to persist. Let's see the example given below:
ObjectOutputStream classAn ObjectOutputStream is used to write primitive data types and Java objects to an OutputStream.Only objects that support the java.io.Serializable interface can be written to streams.Constructor1) public ObjectOutputStream(OutputStream out) throws IOException {}creates an ObjectOutputStream that writes to the specified OutputStream.Example of Java SerializationIn this example, we are going to serialize the object of Student class. The writeObject() method of ObjectOutputStream class provides the functionality to serialize the object. We are saving the state of the object in the file named f.txt.
success Deserilization in javaDeserialization is the process of reconstructing the object from the serialized state.It is the reverse operation of serialization.ObjectInputStream classAn ObjectInputStream deserializes objects and primitive data written using an ObjectOutputStream.Constructor
Example of Java Deserialization
211 ravi |
No comments:
Post a Comment