serialver - serialVersionUID Generator

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.

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

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 java - The Java Program Launcher

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 jpackage - Binary Package Builder

 javadoc - The Java Document Generator

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

 jrunscript - Script Code Shell

Miscellaneous Tools

serialver - serialVersionUID Generator

 jaotc - Java Ahead-Of-Time Compiler

 jwebserver - Java Web Server

 native2ascii - Native-to-ASCII Encoding Converter

 JAB (Java Access Bridge) for Windows

 Archived Tutorials

 References

 Full Version in PDF/EPUB