Generate SerialVersionUID in Java

SerialVersionUID ensures that we are de-serializing the same class which we serialized already. As serialization will allow only the below changes to the Serialized class before de-serializing.

  • Add new variables to the class.
  • Changing a transient variable to a non-transient variable
  • Changing the static variable to a non-static variable.


Lets see the different ways of generating SerialVersionUID

Using serialver command

JDK has build in command “serialver” which builds you the SerialVersionUID for you. Lets see how we create serialversionuid for our Employee class

Command : serialver <<class name>>
D:\Jackson>serialver Employee
Employee:    static final long serialVersionUID = -136067348552556409L;

Using Eclipse IDE

Hover the mouse over the Serialization Class or select the class name and press “ctrl+1” 

SerialVersionUID

Generating SerialVersionUID Manually

You can give in your own number just append at the end

private static final long serialVersionUID = 1L;

Leave a Reply

Your email address will not be published. Required fields are marked *