Home » Java programming language

Java ObjectStreamClass getFields() Method with Example

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

ObjectStreamClass Class getFields() method

  • getFields() method is available in package.
  • getFields() method is used to return all the named fields of this ObjectStreamClass.
  • getFields() 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.
  • getFields() method does not throw an exception at the time of returning named fields.


    public ObjectStreamField[] getFields();


  • It does not accept any parameter.

Return value:

The return type of the method is ObjectStreamField [], it returns an array of the named ObjectStreamField object that contain all the fields when exists.


// Java program to demonstrate the example 
// of ObjectStreamField[] getFields()
// method of ObjectStreamClass

import java.util.*;

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

  // By using getFields() method is to return
  // the fields of this class
  ObjectStreamField[] osf_stm = o_stm.getFields();

  for (int i = 0; i < osf_stm.length; ++i)
   System.out.println("o_stm.getFields(): " + osf_stm[i]);


o_stm.getFields(): Z areFieldsSet
o_stm.getFields(): I firstDayOfWeek
o_stm.getFields(): Z isTimeSet
o_stm.getFields(): Z lenient
o_stm.getFields(): I minimalDaysInFirstWeek
o_stm.getFields(): I nextStamp
o_stm.getFields(): I serialVersionOnStream
o_stm.getFields(): J time
o_stm.getFields(): [I fields
o_stm.getFields(): [Z isSet
o_stm.getFields(): Ljava/util/TimeZone; zone


Comments and Discussions



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

© some rights reserved.