Home »
Java programming language
Java ObjectStreamField getName() Method with Example
ObjectStreamField Class getName() method: Here, we are going to learn about the getName() method of ObjectStreamField Class with its syntax and example.
Submitted by Preeti Jain, on April 12, 2020
ObjectStreamField Class getName() method
- getName() method is available in java.io package.
- getName() method is used to get the name of this ObjectStreamField field.
- 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 denoting the name of the serializable field.
Example:
// Java program to demonstrate the example
// of String getName() method
// of ObjectStreamField
import java.io.*;
import java.util.*;
public class GetNameOfOSF {
public static void main(String[] args) {
// Instantiates ObjectStreamClass for Calendar
ObjectStreamClass o_sc = ObjectStreamClass.lookup(Calendar.class);
// By using getField() method is to get the field
// value from Calendar
ObjectStreamField field1 = o_sc.getField("isTimeSet");
ObjectStreamField field2 = o_sc.getField("isSet");
// By using getName() method is to returm
// the name of the field
String field1_name = field1.getName();
System.out.println("field1.getName(): " + field1_name);
String field2_name = field2.getName();
System.out.println("field2.getName(): " + field2_name);
}
}
Output
field1.getName(): isTimeSet
field2.getName(): isSet