How can a Sub-Class of Serializable Super Class Avoid Serialization?

How can a Sub-Class of Serializable Super Class Avoid Serialization? If Serializable Interface is Implemented by the Super Class of a Class, how can the Serialization of the Class be Avoided? In Java, if the super class of a class is implementing Serializable interface, it means that it is already serializable. Since, an interface cannot … Read more

Is it Possible to Customize the Serialization Process? How can we Customize the Serialization Process

Yes, the serialization process can be customized. When an object is serialized, objectOutputStream.writeObject (to save this object) is invoked and when an object is read, ObjectInputStream.readObject () is invoked. What most people do not know is that Java Virtual Machine provides you with an option to define these methods as per your needs. Once this … Read more

How to Serialize a Collection in Java? How to Serialize a ArrayList, Hashmap or Hashset object in Java

All standard implementations of collections List, Set and Map interface already implement java.io.Serializable. All the commonly used collection classes like java.util.ArrayList, java.util.Vector, java.util.Hashmap, java.util.Hashtable, java.util.HashSet, java.util.TreeSet do implement Serializable. This means you do not really need to write anything specific to serialize collection objects. However you should keep following things in mind before you serialize … Read more

Why does Serialization NOT Save the Value of Static Class Attributes? Why Static Variables are not Serialized

The Java variables declared as static are not considered part of the state of an object since they are shared by all instances of that class. Saving static variables with each serialized object would have following problems It will make redundant copy of same variable in multiple objects which makes it in-efficient. The static variable … Read more

What are Transient Variables? What Role do they Play in Serialization Process

The transient keyword in Java is used to indicate that a field should not be serialized. Once the process of de-serialization is carried out, the transient variables do not undergo a change and retain their default value. Marking unwanted fields as transient can help you boost the serialization performance. Below is a simple example where … Read more