Q: My question is if i will pass the boolean parameter as false then is there any chance that the static block of the class which is going to be loaded using forName method will not going to be executed. Also what is the actual purpose of the second boolean parameter in the forName(String cName, boolean b,ClassLoader load) method?
If b is false then the loaded class will not be initialized unless it has previously been loaded and initialized. So if forName is called and the class hasn't been previously initialized then the static initializer block(s) will not be called but it will get called when you first attempt to use the class.
It's purpose is so you can load a class without having to immediately initialize it - ie you delay the initialization until a future time when the class is first used.
Joined: Oct 30, 2012
subject: forName method with reference to the static block