Example usage for java.lang Class getName

List of usage examples for java.lang Class getName

Introduction

In this page you can find the example usage for java.lang Class getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = Void.TYPE;
    String name = cls.getName(); // void
}

From source file:PrimsDotClass.java

public static void main(String[] args) {
    Class c = int.class;
    System.out.println(c.getName());
    Method[] methods = c.getMethods();
    System.out.println(c.getName() + " has " + methods.length + " methods");
}

From source file:ClassInfoDemo1.java

public static void main(String[] args) {
    String s = "";

    Class c = s.getClass();
    System.out.println(c.getName());

    c = new ClassInfoDemo1().getClass();
    System.out.println(c.getName());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = java.lang.String.class;
    String name = cls.getName();
    System.out.println(name);/*  w  ww . jav a  2  s  .  co  m*/

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = java.util.Map.Entry.class;
    String name = cls.getName();
    System.out.println(name);//  www . j av a  2  s  .c o m
}

From source file:ClassInfoDemo2.java

public static void main(String[] args) {
    Class c = String.class;
    System.out.println(c.getName());

    c = ClassInfoDemo2.class;
    System.out.println(c.getName());

    c = double.class;
    System.out.println(c.getName());

    c = float[].class;
    System.out.println(c.getName());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = java.util.Map.Entry.class;
    String name = cls.getName();
    if (name.lastIndexOf('.') > 0) {
        name = name.substring(name.lastIndexOf('.') + 1); // Map$Entry
        name = name.replace('$', '.'); // Map.Entry
    }/*from   ww  w.j a va2 s  .c  om*/
}

From source file:superClass.java

public static void main(String args[]) {
    superClass val1 = new superClass();
    subClass val2 = new subClass();
    Class cls = val1.getClass();
    System.out.println(cls.getName());

    cls = cls.getSuperclass();/* w w w  .ja  v a 2 s  . c om*/
    System.out.println(cls.getName());

    cls = val2.getClass();
    System.out.println(cls.getName());

}

From source file:Main.java

public static void main(String[] args) {
    Class cls = Thread.class;
    System.out.println("Class = " + cls.getName());

    Class[] c = cls.getClasses();
    System.out.println("Classes = " + Arrays.asList(c));

    // returns an array of interfaces
    Class[] i = cls.getInterfaces();
    System.out.println("Interfaces = " + Arrays.asList(i));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class cls = Class.forName("java.lang.String");
    // returns the ClassLoader object associated with this Class.
    ClassLoader cLoader = cls.getClassLoader();

    if (cLoader == null) {
        System.out.println("The default system class was used.");
    } else {/*from w  w w  .ja  va 2 s. c  om*/
        // returns the class loader
        Class loaderClass = cLoader.getClass();
        System.out.println(loaderClass.getName());
    }
}