Java Tools Tutorials - Herong's Tutorial Examples - v6.23, by Herong Yang
Miscellaneous Tools
This chapter provides provides a tutorial example on how to use 'serialver' command to generate a unique 'serialVersionUID' value for any given serializable Java class.
__chapterToc__
What Is "serialver"? - "serialver" is a command line tool that generates a unique value for "serialVersionUID" for a given Java class code.
If you have %java_home%\bin directory included in "path" the environment variable, you can run "serialver" to get the usage information:
herong> serialver use: serialver [-classpath classpath] [classname...]
1. Try "serialver" on the Hello.java class. It gives an error: "Class Hello is not Serializable".
herong> type Hello.java class Hello { public static void main(String[] a) { System.out.println("Hello world!"); } } herong> javac Hello.java herong> serialver Hello Class Hello is not Serializable.
2. Try "serialver" on a serializable class, HelloSerializable.java. I get a serialVersionUID value.
herong> type HelloSerializable.java import java.io.Serializable; class HelloSerializable implements Serializable { public static void main(String[] a) { System.out.println("Hello world! - Serializable"); } } herong> javac HelloSerializable.java herong> serialver HelloSerializable HelloSerializable: private static final long serialVersionUID = 2133400551086625355L;
3. Put the serialVersionUID value into the class source code to make it complete.
herong> type HelloSerializable.java import java.io.Serializable; class HelloSerializable implements Serializable { private static final long serialVersionUID = 2133400551086625355L; public static void main(String[] a) { System.out.println("Hello world! - Serializable"); } }
Conclusion: To implement a "Serializable" Java class, you need a unique serialVersionUID value, which can be generated by the "serialver" tool.
Table of Contents
javac - The Java Program Compiler
java - The Java Program Launcher
jpackage - Binary Package Builder
javadoc - The Java Document Generator
jdeps - The Java Class Dependency Analyzer
jdeprscan - The Java Deprecated API Scanner
jcmd - The JVM Diagnostic Tool
jconsole - Java Monitoring and Management Console
jstat - JVM Statistics Monitoring Tool
jhsdb - The Java HotSpot Debugger
jvisualvm (Java VisualVM) - JVM Visual Tool
javap - The Java Class File Disassembler
keytool - Public Key Certificate Tool
jrunscript - Script Code Shell
►serialver - serialVersionUID Generator
jaotc - Java Ahead-Of-Time Compiler
native2ascii - Native-to-ASCII Encoding Converter