Java Reference
In-Depth Information
$ serialver SerializableUser
SerializableUser: static final long serialVersionUID = -8339341455288589756L;
Notice how the addition of the field changed the serialVersionUID ! Now, if I had wanted
this class to evolve in a compatible fashion, here's what I should have done before I started
expanding it. I copy and paste the original serialver output into the source file (again using
an editor to insert a line before the last line):
// The following is the line I added to SerializableUser.java
private static final long serialVersionUID = -7978489268769667877L;
$ javac SerializableUser.java
$ serialver SerializableUser
SerializableUser: static final long serialVersionUID = -7978489268769667877L;
$
Now all is well: I can interchange serialized versions of this file.
Note that serialver is part of the “object serialization” mechanism, and, therefore, it is
meaningful only on classes that implement the Serializable interface described in Saving
and Restoring Java Objects .
Note also that some developers use serialVersionUID values that start at 1 (a choice
offered by some IDEs when they note that a class that appears to be serializable lacks a
serialVersionUID ), and then simply increment it by one each time the class changes in an
incompatible way.
Reading and Writing JAR or ZIP Archives
Problem
You need to create and/or extract from a JAR archive or a file in the well-known ZIP
Archive format, as established by PkZip and used by Unix zip/unzip and WinZip.
Solution
You could use the jar program in the Java Development Kit because its file format is identic-
al to the ZIP format with the addition of the META-INF directory to contain additional struc-
tural information. But because this is a book about programming, you are probably more in-
Search WWH ::




Custom Search