Example usage for java.lang Class forName

List of usage examples for java.lang Class forName

Introduction

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

Prototype

@CallerSensitive
public static Class<?> forName(String className) throws ClassNotFoundException 

Source Link

Document

Returns the Class object associated with the class or interface with the given string name.

Usage

From source file:Main.java

public static void main(String[] unused) {
    try {//from  w  w w  .  j  a  v a2 s  . c  o m
        Class d = Class.forName("java.util.Date");
        System.out.println(d.getDeclaredAnnotations().length);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:MySQLJDBCDriverTest.java

public static void main(String[] args) {
    try {//from w w w .java2  s  .  c  o  m
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        System.out.println("Good to go");
    } catch (Exception E) {
        System.out.println("JDBC Driver error");
    }
}

From source file:Main.java

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

    Class cls = Class.forName("java.lang.Integer");

    // returns the name and package of the class
    System.out.println("Class = " + cls.getName());
    System.out.println("Package = " + cls.getPackage());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class cc = null;/*from  w  ww  .  j av a  2 s  .c  o m*/
    cc = Class.forName("Main.class");
}

From source file:Main.java

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

    Class cls = Class.forName("Main");

    ClassLoader cLoader = cls.getClassLoader();

    Class cls2 = Class.forName("java.lang.Thread", true, cLoader);

    System.out.println("Class = " + cls.getName());
    System.out.println("Class = " + cls2.getName());

}

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 {//ww  w . j a v  a2s .  c  o  m
        // returns the class loader
        Class loaderClass = cLoader.getClass();
        System.out.println(loaderClass.getName());
    }
}

From source file:Main.java

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

    Class cls = Class.forName("java.lang.String");

    Class[] classes = cls.getClasses();
    for (int i = 0; i < classes.length; i++) {
        System.out.println("Class found = " + classes[i].getName());
    }/*from  w w  w  .  ja va  2  s .c  o  m*/

}

From source file:Main.java

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

    Class cls = Class.forName("MyClass");

    Class[] classes = cls.getDeclaredClasses();
    for (int i = 0; i < classes.length; i++) {
        System.out.println("Class = " + classes[i].getName());
    }/*from  w  w  w . j a v  a2s.  c  o m*/

}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Class c = Class.forName("java.awt.Dimension");

    Field fields[] = c.getFields();
    for (int i = 0; i < fields.length; i++) {
        System.out.println(fields[i].toGenericString());
    }//from ww w  .  j  ava 2s  .  c  o  m
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Class c = Class.forName("java.awt.Dimension");

    Field fields[] = c.getFields();
    for (int i = 0; i < fields.length; i++) {
        System.out.println(fields[i].toString());
    }// ww w .  j a v a  2s  .  co m
}