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

Is a class a subclass of itself?

805


Explain ioc concept?

835


To identify IDL language what mapping mechanism is used?

3629


What you mean by COM and DCOM?

805


What do you need to set-up a cluster with jboss?

794






AS a developer will u create a data source in connection pool? If so how will u do that, how to access the object from connection pool using IRAD tool?

1868


What are transaction attributes?

811


Can I run seam outside of jboss as?

807


Do I need to import javlang package any time? Why ?

833


How can I avoid validating a form before data is entered?

720


What are callback interfaces?

786


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

760


What is the argument type of a programs main() method?

781


Difference between swing and awt?

811


What class is used to create Server side object ?

1897