Class.forName() in Java | Core Java Tutorials

This Core Java Tutorials “Class.forName()” post is providing clear information about forName() static method available in class Class and how to load class dynamically in Java application.


Class Loading:

  • Generally Class will be loaded @ runtime in java application.
  • But compiler checks whether the class definition is available or not.
  • If Definition is not available, compiler will give error message.
  • As a programmer, we can understand whether the class is loading or not into JVM using static block.
  • Static block executes implicitly at the time of class loading.
  • Following program describes that compiler checks about definition of class.



How to load to class @ runtime :

  • java.lang package is providing a pre-defined class named as “Class”.
  • Class is having pre-defined method called forName().
  • forName() is used to load the class @ runtime.


Following Program explains clearly how to load the class @ runtime:



Share this