This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Class.forName("").getNewInstance().
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.
But that will only work if the JDBC driver uses the ServiceLoader mechanism; if it doesn't (and there are plenty of old drivers around that don't) Class.forName is still the way to go.