Home Java Reflect Retrieving the class name through Reflection API
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Retrieving the class name through Reflection API

Advertisement
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.

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

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 28, 2008

Related Tutorials

Ask Questions?    Discuss: Retrieving the class name through Reflection API  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com