NotSerializableException in java when and how does it occur?

This post is  about the NotSerializableException in java.

So, serialization is the process where the state of the object is transformed into a stream of bits and vice-versa.

This exception NotSerializableException occurs when a POJO is doesn’t implements Serializable interface.

When you are trying to write a object into a file with the help of ObjectOutputStream.writeObject(). It checks for whether the object is serialized or not. If the object is not serialized then it throws the exception.

So, on serialization all the instance variables object state will be serialized except transient variablea and static.

In serialization we can find the serial version id by using

Open command prompt go to the complied location of the class file.
Type-> serialver classname.
As below you can get the serial version UID.

C:UsersPraveenDesktop>serialver A
A: static final long serialVersionUID = 1847304848424810035L;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s