Java.io - SPLessons

Java.io ObjectStreamField

Home > Lesson > Chapter 33
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Java.io ObjectStreamField

Java.io ObjectStreamField

shape Introduction

The Java.io ObjectStreamField is the class used to give the description on serializable field. To declare the serializable field in class an array of Java.io ObjectStreamField is used.

Class Declaration

shape Declaration

Java.io ObjectStreamField class is declared below: Public class ObjectStreamField extends Object implements Comparable<Object>

Class Constructors

shape Table

Constructor Description
ObjectStreamField(String name, Class<?>type) The function of this constructor is to create the field with represented type.
ObjectStreamField (String name, Class<?>type, boolean unshared) The function of this constructor is to field with represented name and type.

Class Methods

shape Table

Method Description
String toString To abstract path name the method returns the pathname string.
String getName() The files or directories which are denoted by its abstract pathname are named by this method.
Class<?> getType() The function of this method is to retutn the type of  field.
int compareTo(Object obj) The function of this method is compares the two object stream fields.
Boolean isUnshared() The function of this method is to check that the object stream represents the serializable field are not.

Inherited Methods

shape Description

From the following classes, methods are inherited the ObjectStreamField class.
  • Java.io.Object

shape Examples

Usage of Boolean isUnshared() method. [c]import java.io.*; public class ObjectStreamField { public static void main(String[] args) { // creating a new object stream class for Integers ObjectStreamClass osc = ObjectStreamClass.lookup(Integer.class); // To get the field value from Integer class ObjectStreamField field = osc.getField("value"); // To check if field is unshared or shared System.out.println("" + field.isUnshared()); } }[/c] The result will be as follows. Output [c]false [/c] ObjectStreamField.java [c]import java.io.*; public class ObjectStreamField { public static void main(String[] args) { // creating a new object stream class for Integers ObjectStreamClass osc = ObjectStreamClass.lookup(Integer.class); // To get the field value from Integer class ObjectStreamField field = osc.getField("value"); // To get the type of the field System.out.println("" + field.getType()); } }[/c] Output The result will be as follows. [c]int[/c]

Summary

shape Key Points

  • The Java.io ObjectStreamField is the class used to give the description on serializable field.
  • To declare the serializable field in class an array of object stream field is used.