Home »
Java programming language
Java ObjectStreamClass getName() Method with Example
ObjectStreamClass Class getName() method: Here, we are going to learn about the getName() method of ObjectStreamClass Class with its syntax and example.
Submitted by Preeti Jain, on April 12, 2020
ObjectStreamClass Class getName() method
- getName() method is available in java.io package.
- getName() method is used to get the name of the ObjectStreamClass class defined by the descriptor and it represents the name in such a format used by getName() method of "Class" class.
- getName() 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.
- getName() method does not throw an exception at the time of returning name.
Syntax:
public String getName();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of the method is String, it returns String that denotes the name of the class.
Example:
// Java program to demonstrate the example
// of String getName() method of
// ObjectStreamClass
import java.io.*;
import java.util.*;
public class GetName {
public static void main(String[] args) {
// Instantiates ObjectStreamClass for
// and Calendar
ObjectStreamClass o_stm = ObjectStreamClass.lookup(Calendar.class);
// By using getName() method is to return
// the name of the class
String name = o_stm.getName();
// Display name
System.out.println("o_stm.getName(): " + name);
}
}
Output
o_stm.getName(): java.util.Calendar