Home » Java programming language

Java ObjectStreamClass getName() Method with Example

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

ObjectStreamClass Class getName() method

  • getName() method is available in package.
  • getName() method is used to get the name of the ObjectStreamClass class defined by the descriptor and it represents the name in such a format used by getName() method of "Class" class.
  • getName() 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.
  • getName() method does not throw an exception at the time of returning name.


    public String getName();


  • It does not accept any parameter.

Return value:

The return type of the method is String, it returns String that denotes the name of the class.


// Java program to demonstrate the example 
// of String getName() method of 
// ObjectStreamClass

import java.util.*;

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

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

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


o_stm.getName(): java.util.Calendar


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.