Home » Java programming language

Java ObjectStreamClass getField() Method with Example

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

ObjectStreamClass Class getField() method

  • getField() method is available in java.io package.
  • getField() method is used to return the field of this ObjectStreamClass by the given field name (fi_na).
  • getField() 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.
  • getField() method does not throw an exception at the time of returning named field.


    public ObjectStreamField getField(String fi_na);


  • String fi_na – represents the name of the returned field.

Return value:

The return type of the method is ObjectStreamField, it returns the ObjectStreamField object of the named field when exists otherwise it returns null when no named field exists.


// Java program to demonstrate the example 
// of ObjectStreamField getField(String fi_na)
// method of ObjectStreamClass

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

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

  // By using getField() method is to return
  // the field of this class by name
  ObjectStreamField o_sf1 = o_stm.getField("isTimeSet");
  ObjectStreamField o_sf2 = o_stm.getField("fields");

  // Display o_sf1, o_sf2
  System.out.println("o_stm.getField(isTimeSet): " + o_sf1);
  System.out.println("o_stm.getField(fields): " + o_sf2);


o_stm.getField(isTimeSet): Z isTimeSet
o_stm.getField(fields): [I fields

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.