Retrieving the class name through Reflection API

A more generic way, how to retrieve the name of the class (that is used in the program) that reflects the package name by using the getName() method. Here is an example that provides the proper way to use the getName() method.


 
Ads

Retrieving the class name through Reflection API

     

A more generic way, how to retrieve the name of the class (that is used in the program) that reflects the package name by using the getName() method. Here is an example that provides the proper way to use the getName() method.

Here we create an object of class Fclass and assign the reference of the class java.util.Integer.class to it. Now retrieve the class name (that is included in the program) by using the getName() method.

Here is the code of the Example :

 

 

 

Fclass.java

import java.lang.reflect.*;
public class Fclass{
  public static void main(String[] args){
  Class cls = java.lang.Integer.class;
  String info;
  info = cls.getName()// It will show java.lang.Integer
  System.out.println(info);
  }
}

Here is the output of the Example :

C:\roseindia>javac Fclass.java

C:\roseindia>java Fclass
java.lang.Integer

Download this Example:

Advertisements

Share on Google+Share on Google+

Retrieving the class name through Reflection API

Posted on: February 28, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Retrieving the class name through Reflection API  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads