How to get a Class Object from the Class Name in Java

You can use:

Class c = Class.forName("com.package.MyClass");

And later instantiate an object:

Object obj = c.newInstance();

EDIT: This is just the simplest use case. As indicated in the comments, you will need to consider constructor arguments and exceptions thrown by the initialization process. The JavaDocs for newInstance has all the details.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)