Java Reflection - Java Class.getSimpleName()








Syntax

Class.getSimpleName() has the following syntax.

public String getSimpleName()

Example

In the following code shows how to use Class.getSimpleName() method.

//  w ww.j a  v a 2 s .c  o  m

public class Main {
   public static void main(String[] args) {
     Main c = new Main();
     Class cls = c.getClass();

     // returns the name of the class
     String name = cls.getName();
     System.out.println("Class Name = " + name);
     
     // returns the simple name of the class
     String sname = cls.getSimpleName();
     System.out.println("Class SimpleName = " + sname);     
   }
}

The code above generates the following result.