We have already seen what is the use of Class.forName in Java, now lets see why we use Class.forName in JDBC, lets take an example that we are trying to register MySql driver using Class.forName("com.mysql.jdbc.Driver"). The JVM will try to execute the static block of the Driver class which look like below. … [Read more...]
Use of Class.forName in java
In this article we will learn the uses of Class.forName in Java and how it is used in creating objects dynamically. In general Class.forName is used to load the class dynamically where we doesn't know the class name before hand. Once the class is loaded we will use newInstance() method to create the object dynamically. Lets consider that we have a class "Test", and we make a … [Read more...]