What is Serialization? How Can we avoid Serialization of any fields or methods in a class?

  •  An object's state can be transformed into a byte stream through a process known as serialisation.

  •  Deserialization is the opposite procedure, in which the actual Java object is recreated in memory using a byte stream

 Can we avoid Serialization of any fields or methods in a class?

Yes, we Can avoid it.

The Static and Transient Fields Are Not Serialized

We can mark certain fields as transient if we want to serialize one item but not other objects.

Since the serialisation procedure serialises the object and not the class, which contains all of the static fields, static fields cannot be serialised.

Comments

Popular posts from this blog

Why Pointers are Eliminated in Java?

What is the advancement made in Hashmap in Java 8?

Integer.parseInt(“text”)