What is the use of Class.forName

Answer Posted / naresh

/**
* Returns the <code>Class</code> object associated with
the class or
* interface with the given string name. Invoking this
method is
* equivalent to:
*
* <blockquote><pre>
* Class.forName(className, true, currentLoader)
* </pre></blockquote>
*
* where <code>currentLoader</code> denotes the defining
class loader of
* the current class.
*
* <p> For example, the following code fragment returns the
* runtime <code>Class</code> descriptor for the class named
* <code>java.lang.Thread</code>:
*
* <blockquote><pre>
* Class&nbsp;t&nbsp;= Class.forName("java.lang.Thread")
* </pre></blockquote>
* <p>
* A call to <tt>forName("X")</tt> causes the class named
* <tt>X</tt> to be initialized.
*
* @param className the fully qualified name of
the desired class.
* @return the <code>Class</code> object for the
class with the
* specified name.
* @exception LinkageError if the linkage fails
* @exception ExceptionInInitializerError if the
initialization provoked
* by this method fails
* @exception ClassNotFoundException if the class cannot
be located
*/
public static Class<?> forName(String className)
throws ClassNotFoundException {
return forName0(className, true,
ClassLoader.getCallerClassLoader());
}



Source: Source code copied from Class class of JDK 1.6.

Hope this would be useful.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is a portable component?

1476


Will the general public have access to the infobus apis?

544


What is meant by method chaining?

673


how do you Handle Front End Application data against DB with example?

1493


what is an isolation level?

2225






What restrictions are placed on the values of each case of a switch statement?

547


How is a java object message delivered to a non-java client?

591


To identify IDL language what mapping mechanism is used?

3424


What do you mean by Socket Programming?

561


What is table mutation and how do you avoid it?

1923


Explain what is orm?

689


Which class is the immediate superclass of the menucomponent class?

648


whats is mean by tiles in struts

1640


Explain about RMI Architecture?

623


What is a sessionfactory? Is it a thread-safe object?

700