Home Java Java-get-example Get Class Name
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Get Class Name

Advertisement
In the example given below we will learn how to get name of the particular class with package name. getName() method returns fully qualified name of the particular class in string format.

Get Class Name

     

In the example given below we will learn how to get name of the particular class with package name. getName() method returns fully qualified name of the particular class in string format.

 

 

 

Here is the code:

import java.util.Calendar;
import java.math.BigDecimal;
 
public class GetClassName {
  public static void main(String[] args) {
  Class cl = String.class;
  System.out.println("Class Name: " + cl.getName());

  cl = Object.class;
  System.out.println("Class Name: " + cl.getName());

  cl = Calendar.class;
  System.out.println("Class Name: " + cl.getName());
 
  cl = BigDecimal.class;
  System.out.println("Class Name: " + cl.getName());
  }
}

 

Output will be displayed as:

 

Download Source Code

 

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: October 23, 2008

Related Tutorials

Ask Questions?    Discuss: Get Class Name  

Post your Comment


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