Home » Java programming language

Java ObjectStreamClass lookup() Method with Example

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

ObjectStreamClass Class lookup() method

  • lookup() method is available in java.io package.
  • lookup() method is used to lookup the descriptor for a class that can be serialized.
  • lookup() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
  • lookup() method does not throw an exception at the time of lookup descriptor.

Syntax:

    public static ObjectStreamClass lookup(Class c);

Parameter(s):

  • Class c – represents the class for which to lookup the descriptor.

Return value:

The return type of the method is ObjectStreamClass, it returns the serial version UID of the class defined by this descriptor.

Example:

// Java program to demonstrate the example 
// of ObjectStreamClass lookup(Class c) method 
// of ObjectStreamClass

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

public class LookUp {
 public static void main(String[] args) {
  // Instantiates ObjectStreamClass for 
  // and Calendar 

  // By using lookup() method is to find the 
  // descriptor for the class must implements
  // Serializable interface
  ObjectStreamClass o_stm = ObjectStreamClass.lookup(Calendar.class);

  // By using getName() method is to
  // return the name for the class
  String name = o_stm.getName();

  // Display name
  System.out.println("o_stm.getName(): " + name);
 }
}

Output

o_stm.getName(): java.util.Calendar



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.