Java installation provides 'serialver' command line tool, to get the Serialversionuid of a serialized class.
Open command prompt (or) terminal, type 'serialver' command, you can get the usage help.
$ serialver
use: serialver [-classpath classpath] [-show] [classname...]
Employee.java
import java.io.Serializable;
public class Employee implements Serializable{
int id;
String firstName, lastName;
Employee(int id, String firstName, String lastName){
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
}
$ javac Employee.java
$
$ serialver Employee
Employee: private static final long serialVersionUID = 8478298351518747306L;
You can also specify serialVersionUID of a class by defining the variable serialVersionUID like below.
private static final long serialVersionUID = 1234L;
You may like
Implement pooling functionality for connection objects
Why do we require empty collections?
Why do we require empty iterators?
Difference between System.out and System.err
Is Serializable class has any methods?
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here