How to get a Java Class Object

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");

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments