If you want to instantiate a class for which you have the name, you were already on the right track:
// Remember that this class name tells us, it's in the default package,
// otherwise you would have to use the fully qualified name, for example
// com.mydomain.Test
String className = "Test";
// First we need to get the correct class object
Class<?> clz = Class.forName(className);
// And from this class object, we can create a new instance, in other
// words, a "Test" object:
Test test = (Test)clz.newInstance();
Of course, there are some exceptions that have to be caught (or declared), etc. But I think you get the idea. If you do not want to call the default constructor (the one with no arguments, in other words the equivalent of new Test()
) of your "Test" class, you would have to search the right constructors via the appropriate methods of the Class object (getDeclaredConstructor, etc.etc. - see the API doc for that).