Class ObjectStreamClass in Java

0
69
digitization, transformation, binary
Spread the love

Class ObjectStreamClass in Java

This class is used to represent a class that is being serialized. An ObjectStreamClass object contains the name of a class and its unique version identifier. This class does not have a constructor; we should use the static lookup() method to obtain an ObjectStreamClass object for a given Class object.

When an object is deserialized, its class information is read into an ObjectStreamClass, which is then resolved to a Class if possible. An ObjectStreamClass instance contains the name and version information for a class.

The forClass() instance method performs the opposite operation–it returns the Class object that corresponds to a given ObjectStreamClass.

Most applications never need to use this class.

The class structure of class ObjectStreamClass is given as

public class java.io.ObjectStreamClass extends java.lang.Object implements java.io.Serializable {
// No Constructor
// Class Methods
public static ObjectStreamClass lookup(Class class);
// Public Instance Methods
public Class forClass();
public String getName();
public long getSerialVersionUID();
public String toString(); // Overrides Object
}

The details of the class ObjectStreamClass is given as:

public static ObjectStreamClass lookup(Class class);

public static ObjectStreamClass lookup(Class class) method finds an ObjectStreamClass for the given Class. If the appropriate ObjectStreamClass does not already exist, this method creates an ObjectStreamClass for the given Class. The method returns null if cl is not serializable.
This method returns an ObjectStreamClass that corresponds to the given Class.
Parameter
class-The Class to find.

public Class forClass();

public Class forClass() method returns the Class in the run-time system that corresponds to this ObjectStreamClass. If there is no corresponding class, null is returned.
This method returns the Class that corresponds to this ObjectStreamClass.

public String getName();

public String getName() method returns the name of the class this ObjectStreamClass represents.
This method returns the class name.

public long getSerialVersionUID();

public long getSerialVersionUID() method returns the version of the class this ObjectStreamClass represents.
This method returns the class version.

public String toString(); // Overrides Object

public String toString() method returns a string that contains the class name and version information for this
ObjectStreamClass.
This method returns a string representation of this object.
Apart from these ObjectStreamClass class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)
READ  JSoup A Nice Initiative To Fetch Information From HTML


Spread the love
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

LEAVE A REPLY

Please enter your comment!
Please enter your name here