Query regarding the Class.forname method

why can抰 the following code do the job of 搇ocate, load, and link?which Class.forName(Driver name)

is used to perform?

org.gjt.mm.mysql.Driver driver =new org.gjt.mm.mysql.Driver();

This would locate , load and link by executing the static block

Thanks,

[320 byte] By [Manthan0a] at [2007-11-27 6:33:19]
# 1
That would issue an overhead by unnecessarily creating a new instance.You can also useClass.forName(org.gjt.mm.mysql.Driver.class.getName());instead.
BalusCa at 2007-7-12 17:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
What is the difference between[codeClass.forName("org.gjt.mm.mysql.Driver"); [/code]and[codeClass.forName(org.gjt.mm.mysql.Driver.class.getName()); [/code
Manthan0a at 2007-7-12 17:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
What is the difference betweenClass.forName("org.gjt.mm.mysql.Driver"); andClass.forName(org.gjt.mm.mysql.Driver.class.getName());
Manthan0a at 2007-7-12 17:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
The difference is that you have to import (locate/link) the class explicitly, thus having it directly in the classpath during compilation.
BalusCa at 2007-7-12 17:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
In which case it has to be on the classpath? n what about the other case? Plaeas do reply even in case my questions are sounding stupid.
Manthan0a at 2007-7-12 17:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

Class.forName(org.gjt.mm.mysql.Driver.class.getName());

This requires the class being imported explicitly and available on the classpath during compilation. This isn't the case for the other case.

In both cases though, this class is required in the classpath during runtime.

BalusCa at 2007-7-12 17:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...