Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How is serialization and static data member serialization used in java?


Asked by Caroline Stephenson on Dec 11, 2021 Java



Serialization and static data member Serialization 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 and JMS technologies. The reverse operation of serialization is called deserialization where byte-stream is converted into an object.
Subsequently,
Java Serialization with the static data member. If there is any static data member in a class, it will not be serialized because static is the part of class not object.
Next, Static data members and transient data members are not saved via Serialization process.So, if you don’t want to save value of a non-static data member then make it transient. 4. Constructor of object is never called when an object is deserialized. 5. Associated objects must be implementing Serializable interface.
Similarly,
Static variables are not part of object. When we serialize the object, the static variable (s) are not be serialized. 2. Transient data member: Sometimes, we do not want serialize some data members. Then, we can mark those variables as transient variables. Transient data members are not be serialized.
In addition,
But sometimes, we might want to reuse an object between several JVMs or we might want to transfer an object to another machine over the network. Well, serialization allows us to convert the state of an object into a byte stream, which then can be saved into a file on the local disk or sent over the network to any other machine.