The Class Named Class

There is a class called Class that represents the possibility of making and loading classes in the Java Programming Language. You can make instances of the Class class for the classes and interfaces in a running Java application.

The primitive Java types and the keyword void are represented as Class types.

Class has no public constructor. That is, you cannot write this: Class clazz = new Class();. You can get a Class object for a given class in three different ways.

First, you can use the getClass() method of java.lang.Object. If you have an instance of Object called obj, you can write the following:

Class clazz = obj.getClass();

Second, you can use the class literal, like this:

 Class clazz = java.lang.String.class;  ...

Get Java Garage now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.