In such case, it will return 0 because the data type of id is an integer. Now, id will not be serialized, so when you deserialize the object after serialization, you will not get the value of id. Public class Student implements Serializable The String class and all the wrapper classes implement the java.io.Serializable interface by default. The Serializable interface must be implemented by the class whose object needs to be persisted. The Cloneable and Remote are also marker interfaces. It is used to "mark" Java classes so that the objects of these classes may get a certain capability. Serializable is a marker interface (has no data member and method). It is mainly used to travel object's state on the network (that is known as marshalling). We must have to implement the Serializable interface for serializing the object. The serialization and deserialization process is platform-independent, it means you can serialize an object on one platform and deserialize it on a different platform.įor serializing the object, we call the writeObject() method of ObjectOutputStream class, and for deserialization we call the readObject() method of ObjectInputStream class. The reverse operation of serialization is called deserialization where byte-stream is converted into an object. It is mainly used in Hibernate, RMI, JPA, EJB and JMS technologies. Serialization in Java is a mechanism of writing the state of an object into a byte-stream.
0 Comments
Leave a Reply. |