Java - serialVersionUID

Java Conceptuel Diagram


The serialVersionUID is an ID that must be unique in order to serialize and de-serialize an object.



jdk/bin/serialver -classpath bin java.util.ArrayList


The whole algorithm is specified in the Object Serialization Specification, Section 4.6, Stream Unique Identifiers

Code: The use ObjectStreamClass.getSerialVersionUID to generate the UID on Line 215.Extract of

ByteArrayOutputStream bout = new ByteArrayOutputStream();
// bout collect fingerprint information of the class
MessageDigest md = MessageDigest.getInstance("SHA");
byte[] hashBytes = md.digest(bout.toByteArray());
long hash = 0;
for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) {
	hash = (hash << 8) | (hashBytes[i] & 0xFF);
return hash;

Share this page:
Follow us:
Task Runner