What is a Serial Version UID (serialVersionUID) and why should I use it?

What is a Serial Version UID (serialVersionUID) and why should I use it?

SerialVersionUID is used to ensure that same class(That was used during Serialization) is loaded during Deserialization.serialVersionUID is used for version control of object.
If you have used Serialization then You might have seen serialVersionUID because whenever you implement Serializable interface your IDE will give you warning.

Serialversionuid Syntax:

ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;

serialVersionUID must be Static and final.You can assign any number to it.
Lets see an example:
 

import java.io.Serializable;

public class Emp implements Serializable{

private static final long serialVersionUID = 1L;

int empId;

String empName;

public int getEmpId() {

return empId;

}

public void setEmpId(int empId) {

this.empId = empId;

}

public String getEmpName() {

return empName;

}

public void setEmpName(String empName) {

this.empName = empName;

Read More →