Java IO ObjectStreamField Last Updated : 26 Oct, 2021 Comments Improve Suggest changes Like Article Like Report The Java. io. ObjectStreamField class is a description of a Serializable field from a Serializable interface. This class is serialization’s descriptor for classes. An array of The ObjectStreamFields is utilized to maintain the Serializable fields of a class. It includes the name and serialVersionUID of the class. The Class Declaration for Java IO ObjectStreamField is as - 1. public class ObjectStreamField extends Object // extends Keyword is used 2. public class ObjectStreamField implements Comparable<Object> // implements Keyword is usedConstructors of Java IO ObjectStreamField Following Are The Two Constructors For The Class Java IO ObjectStreamField - Sr. No. ConstructorDescription1ObjectStreamField (String name, Class<?> type)This Constructor Creates a Serializable field with the specified type to it 2ObjectStreamField (String name, Class<?> type, boolean unshared) This Constructor Creates an ObjectStreamField representing a serializable field with the given name and type of itMethods of Java IO ObjectStreamField S.No. Method Method Type Description 1compareTo(Object obj) int This Method is Comparing this field with another ObjectStreamField2getName() String This method gives the name of the field3GetOffset() int This method returns the offset of the field within instance data4getType() Class<?>It gives the type of the field for the get type method5getTypeCode() char This method returns the character encoding of the field type6getTypeString() String This method returns the JVM type Signature7isPrimitive() boolean It returns true if the field has a primitive type8isUnshared() boolean It returns a boolean value indicating whether or not the serializable field represented by this ObjectStreamField instance is unshared.9setOffset( int offset) protected void This method returns offset within the instance of the data10toString() String It returns a string that describes all this fieldExample: Java // Java program to illustrate the working // of the Java IO ObjectStreamField class import java.io.ObjectStreamClass; import java.util.Calendar; public class ObjectStreamClassExample { public static void main(String[] args) { // creating a new object for the stream class for the Integers ObjectStreamClass abc = ObjectStreamClass.lookup(String.class); // getting the value field from ObjectStreamClass for the integers System.out.println("" + abc.getField("value")); // creating new object stream class for the Calendar ObjectStreamClass abc2 = ObjectStreamClass.lookup(Calendar.class); // get the Class instance for abc2 System.out.println("" + abc2.getField("isTimeSet")); } } Output -I value Z isTimeSetExample for Method of Java IO ObjectStreamField ( compareTo(Object obj) ) - The subsequent illustration explains the usefulness of the java.io.ObjectStreamField.compareTo() method - Java // Java program to illustrate the working of the // Java IO ObjectStreamField(compareTo(Object obj)) class import java.io.*; public class ObjectStreamField_ShowDemo { public static void main(String[] args) { // creating a new object stream class for The Integers ObjectStreamClass xyz = ObjectStreamClass.lookupAny(Integer.class); // getting the field value from Integer class ObjectStreamField field = xyz.getField("value"); // creating a new object stream class for floats ObjectStreamClass xyz2 = ObjectStreamClass.lookupAny(Float.class); // getting the field value from Integer class ObjectStreamField field2 = xyz.getField("value"); // comparing with another field System.out.println("" + field.compareTo(field2)); } } Output :0 Comment More infoAdvertise with us Next Article Java IO ObjectStreamField K khurpaderushi143 Follow Improve Article Tags : Java Java-IO package Practice Tags : Java Similar Reads Java.io.ObjectStreamClass in Java This class is serialization's descriptor for classes. It contains the name and serialVersionUID of the class. The ObjectStreamClass for a specific class loaded in this Java VM can be found/created using the lookup method. It extends class Object and implement serialisable. Fields: static ObjectStrea 3 min read Stream In Java Stream was introduced in Java 8, the Stream API is used to process collections of objects. A stream in Java is a sequence of objects that supports various methods that can be pipelined to produce the desired result. Use of Stream in JavaThe uses of Stream in Java are mentioned below:Stream API is a 7 min read Java IO Tutorial Java programming language comes with a variety of APIs that helps the developers to code more efficiently. One of those APIs is Java IO API. Java IO API helps the users to read and write data. In simple words, we can say that the Java IO helps the users to take the input and produce output based on 15+ min read Java 8 Stream Introduction to Stream, Java Intstream, Jaa Longstream , Java DoublestreamanyMatch() noneMatch() mapToLong() findAny()forEachOrdered() forEach() allMatch() filter() findFirst() flatMapToInt() mapToInt() map() peek() counting()Iterator()Generate()Skip()SummaryStatistics()Builder()Empty()Stream toArra 1 min read Stream of() method in Java Stream of(T t) Stream of(T t) returns a sequential Stream containing a single element. Syntax : static Stream of(T t) Parameters: This method accepts a mandatory parameter t which is the single element in the Stream. Return Value: Stream of(T t) returns a sequential Stream containing the single spec 2 min read Like