You are on page 1of 3

Serialization:

1)What is Serialization and De-Serialization?

Ans The process of converting an object from java supported form to n/w or file supported form is
called Serialization.

The process of converting an object from n/w or file form to java supported object is called
De-Serialization.

2)When NotSerializableException occurs?

Ans if we not import serializable interface

3)Marker Interface?

Ans It is an empty interface (no field or methods).where the required ability provided
automatically by jvm.

EX:

java.lang.Cloneable.
java.io.Serializable.
java.rmi.Remote.
java.util.EventListener.

4)Transient Key word?

Ans transient : It is a modifier which is applicable only for variables.

At the time of serialization if we dont want to save the value of a variable to meet security
constranints.

At the time of serialization JVM ignores the original value and stores default value to a file.

Note: In java there is no concept of implmenting super class as serializable.Ex:Object class.(To


serialize child class object parent need not to be serializable)

1)Even though parent class doesn't implement serializable interface we can serialize child class
object.If the child class implements serializable interface i.e.,to serialize child class object,parent class
need not to be serialize.

2)at the time of serialization jvm check is any instance variable inheriting from non serializable parent
or not.And jvm ignores original value and save default value to the file.
3)At the time of deserialization jvm will check if any parent is non serializable or not. If any parent is
non serializable jvm executes instance control flow in that non serializable parent and share it
instance varialbles to the current.

4)To execute instance control flow execution of non-serializable parent jvm will always invoke no
argument constructor.Hence every non-serializable class should compulsory contain no arugment
constructor.Other wise we will get runtime exception saying InvalidClassException.

1)Identification of instance members.

2)execution of instance variables assignes instance blocks.

3)execution of constructor.

Note: Compiler will generate constructors.

NOTE:In Serialization both and sender and reciver should has .class file at the begining only.just state
of object is travelling from sender to reciver.

At the time of serialization with every object sender side jvm will save a uid.jvm is responsible to
generate this uid based on .class file.At the time of deserialization reciver side jvm will compare uid
associated with object with local class uid.if both are matched then only deserialization will be
formed.other wise we will get runtime exception saying : Invalid class Exception.This unique identifier
is nothing but SerialVersionUID.

Problems of depending on default serialVersionId:

1)both sender and reciver should use same JVM with respect to vendor and platform and
version.other wise reciver unable to deserialize because of different serialversionid.

2)both sender and reciver should use same .class version.after serialization if there is any change
in .class file at reciver side then reciver unable to deserialze.

3)To generate serial version id internally JVM may use complex algorithm which may create
perfomance problem.

we can solve above problem by configuring our own serial version uid.

we can configure our own serial version uid as follows:

private static final long serialVersionUID = 1l;

after serialization if we perform any change to the .class file at reciver side we wont get any problem
at the time of deserialization.In this case sender and reciver not required to maintain same JVM
versions.

NOTE : Some ides prompt programmer to enter serialversionuid explicitly.Some ides may generate
serialversionuid automatically.
Clonable:

You might also like