Java Class.getName()

Syntax

Class.getName() has the following syntax.

public String getName()

Example

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


/*w ww  . j a  v a 2s  .  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();
     System.out.println(name);
   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable