This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am not able to understand the difference , I mean to say where should I use only Class.forName("") & where should I go for
Suppose I am loading the driver in JDBC , so which procedure is better ?
I believe the question is related to an old pre-Java 1.2 problem when loading Database Drivers.
When the JDBC Driver Class is loaded, it should register itself with the DriverManager, no surprise there.
While calling Class.forName() should load the Class, pre-Java 1.2 it did not load the Class until an instance of the Class was created, hence all of the JDBC examples from that era, and copied from there without comprehension, includes the Class.forName().newInstance() rather than just Class.forName()
As far as I know, in the latest version of the JDBC API it's not necessary at all anymore to call Class.forName("...") for JDBC drivers - a new mechanism was added to JDBC so that it's able to find JDBC drivers that are on the classpath by itself, without the need for the JDBC driver class to be loaded explicitly.