Java Reflection - Java Class.getName()


Class.getName() has the following syntax.

public String getName()


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

/*w w w  .  j a v  a  2  s. c  o m*/
public class Main {

   public static void main(String[] args) {

     Main cl = new Main();
     Class c1Class = cl.getClass();

     // returns the name of the class
     String name = c1Class.getName();

The code above generates the following result.