You can use Class.forName with a few extra parameters to get around the limitations in Rahul's answer.
Class.forName(String) does load and initialize the class, but Class.forName(String, boolean, ClassLoader) does not initialize it if this second parameter is false.
If you have a class like this:
public class Foo { static { System.out.println("foo loaded and initialized"); } }
and you have
Class.forName("com.example.Foo")
console output will be foo loaded and initialized .
If you use
Class.forName("com.example.Foo", false, ClassLoader.getSystemClassLoader());
you will see that the static initializer is not being called.
source share