As far as i know, there are 4 ways to get the Java Class object.

1. “.class”

Class cls = Address.class;

2. object.getClass()

Address address = new Address();
Class cls = address.getClass();

3. Class.forName()

Class cls = Class.forName("com.mkyong.io.Address");

4. ClassLoader.loadClass()

ClassLoader cl = ClassLoader.getSystemClassLoader();
Class  cls = cl.loadClass("com.mkyong.io.Address");
Tags :