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

Which container method is used to cause a container to be laid out and redisplayed?

671


What are the design considerations while making a choice between using interface and abstract class?

552


What is the form of storage space in java?

1748


What is meant by method chaining?

668


What are JTA/JTS and how they used by client?

1723






Will the general public have access to the infobus apis?

536


When a thread blocks on i/o, what state does it enter?

580


Which javutil classes and interfaces support event handling?

592


What is colon_pkg_prefixes and what is its use?

2004


the same information whether it will connect to the database or it will be used previous information?

579


What modifiers may be used with an interface declaration?

563


What are local interfaces? Describe.

707


whats is mean by tiles in struts

1635


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?

1651


What is the highest-level event class of the event-delegation model?

582