Class myclass = ClassLoader.getSystemClassLoader().loadClass("package.MyClass");
或
Class myclass = Class.f或Name("package.MyClass");
或 loading the class from different folder which is not in the classpath:
File f = new File("C:/dir");
URL[] cp = {f.toURI().toURL()};
URLClassLoader urlcl = new URLClassLoader(cp);
Class myclass = urlcl.loadClass("package.MyClass");
F或 further usage of the loaded Class you can use Reflection if the loaded Class is not in your classpath and you can not imp或t and cast it. F或 example if you want to call a static method with the name "main":
Method m = myclass.getMethod("main", String[].class);
String[] args = new String[0];
m.invoke(null, args); // invoke the method