Java.io.ObjectStreamClass.getName() Method



Description

The java.io.ObjectStreamClass.getName() method returns the name of the class described by this descriptor. This method returns the name of the class in the format that is used by the Class.getName() method.

Declaration

Following is the declaration for java.io.ObjectStreamClass.getName() method.

public String getName()

Parameters

NA

Return Value

This method returns a string representing the name of the class.

Exception

NA

Example

The following example shows the usage of java.io.ObjectStreamClass.getName() method.

package com.tutorialspoint;

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

public class ObjectStreamClassDemo {
   public static void main(String[] args) {
   
      // create a new object stream class for Integers
      ObjectStreamClass osc = ObjectStreamClass.lookup(Integer.class);

      // get the name of the class and print it
      System.out.println("" + osc.getName());

      // create a new object stream class for Calendar
      ObjectStreamClass osc2 = ObjectStreamClass.lookup(Calendar.class);

      // get the name of the class and print it
      System.out.println("" + osc2.getName());
   }
}

Let us compile and run the above program, this will produce the following result −

java.lang.Integer
java.util.Calendar
java_io_objectstreamclass.htm
Advertisements