This program shows how to use getSerialVersionUID : Serialization « File Input Output « Java






This program shows how to use getSerialVersionUID

      
import java.io.ObjectStreamClass;

/**
 * This program shows how to use getSerialVersionUID for a class that isn't in a
 * package and thus not findable to the normal "serialver" tool.
 * 
 * @author Ian Darwin, http://www.darwinsys.com/
 */
public class GetSerVersUID {
  static final String ident = "$Id: GetSerVersUID.java,v 1.5 2004/02/09 03:33:53 ian Exp $";

  public static void main(String[] av) throws Exception {

    // First we construct a Class object for the given class
    Class cl = Class.forName("Candidate");

    // Then an ObjectStreamClass for the given class
    ObjectStreamClass ocl = ObjectStreamClass.lookup(cl);

    // And use the ObjectStreamClass to get the Class'
    // unique SerialVersionUID
    System.out.println("For class " + cl);
    System.out.println("static final long serialVersionUID = "
        + ocl.getSerialVersionUID() + "L;"); // must be long

    // And just for reference...
    System.out.println("(Must range from " + Long.MIN_VALUE + " to "
        + Long.MAX_VALUE + ".)");
  }
}

           
         
    
    
    
    
    
  








Related examples in the same category

1.Serialization with ObjectInputStream and ObjectOutputStream
2.Object SerializationObject Serialization
3.Serial Demo
4.Create a serialized output file
5.Reconstructing an externalizable objectReconstructing an externalizable object
6.Simple use of Externalizable and a pitfallSimple use of Externalizable and a pitfall
7.Serializable
8.Serializer class
9.Working with Serialization
10.Assists with the serialization process and performs additional functionality based on serialization.
11.Computes all the class serialVersionUIDs under the jboss home directory.
12.Serializable Enumeration
13.Serialization Utilities
14.This program demonstrates the transfer of serialized objects between virtual machines
15.A class whose clone method uses serialization
16.Writes a serialized version of obj to a given file, compressing it using gzip.
17.Reads a serialized object from a file that has been compressed using gzip.
18.Serialized File Util
19.Serializes an object to a file, masking out annoying exceptions.