I have read about static initializers online and understood that it's just another way of initializing variables(static variables only). I also read about static and dynamic class loading.
static class loading means using the new keyword and creating an instance of the class and dynamic class loading means using Class.forName() method. Also, loading means creating the .class's object right? Am I correct? Please correct me if I am wrong.
I do not understand why we need Class.forName() , the dynamic class loading when we can already load our class statically. Can someone please tell me why?
We use Class.forName() and the like to load classes whose names we don't know when our code is compiled. For example, imagine you're writing a servlet container like Tomcat. You read a web.xml file and it tells you the class name of a servlet. How do you instantiate that servlet? By loading the class with Class.forName(), and using Class.newInstance() to create one.
I hate the term "static class loading". I've heard it used before but it's an inappropriate and misleading term. All class loading is dynamic; it always happens at runtime.