Home » Java programming language

Java ObjectStreamClass getSerialVersionUID() Method with Example

ObjectStreamClass Class getSerialVersionUID() method: Here, we are going to learn about the getSerialVersionUID() method of ObjectStreamClass Class with its syntax and example.
Submitted by Preeti Jain, on April 12, 2020

ObjectStreamClass Class getSerialVersionUID() method

  • getSerialVersionUID() method is available in java.io package.
  • getSerialVersionUID() method is used to get the serial version UID for this ObjectStreamClass class and the uid defines a set of classes with the same name that has evolved from a common root class and satisfies to be serialized and deserialized during a common format.
  • getSerialVersionUID() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getSerialVersionUID() method does not throw an exception at the time of returning serial version UID.

Syntax:

    public long getSerialVersion();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is long, it returns the serial version UID of the class defined by this descriptor.

Example:

// Java program to demonstrate the example 
// of long getSerialVersion() method of 
// ObjectStreamClass

import java.io.*;
import java.util.*;

public class GetSerialVersionUID {
 public static void main(String[] args) {
  // Instantiates ObjectStreamClass for 
  // and Calendar
  ObjectStreamClass o_stm = ObjectStreamClass.lookup(Calendar.class);

  // By using getSerialVersionUID() method is to return
  // the serial version uid of this class
  long svuid = o_stm.getSerialVersionUID();

  // Display svuid
  System.out.println("o_stm.getSerialVersionUID(): " + svuid);
 }
}

Output

o_stm.getSerialVersionUID(): -1807547505821590642


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.