What is the use of Class.forName

Answer Posted / amit beriwal

forName

public static Class forName(String className)
throws ClassNotFoundException

Returns the Class object associated with the class or
interface with the given string name. Invoking this method
is equivalent to:

Class.forName(className, true, currentLoader)


where currentLoader denotes the defining class loader of
the current class.

For example, the following code fragment returns the
runtime Class descriptor for the class named java.lang.Thread:

Class t = Class.forName("java.lang.Thread")


A call to forName("X") causes the class named X to be
initialized.

Parameters:
className - the fully qualified name of the desired
class.
Returns:
the Class object for the class with the specified name.
Throws:
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization
provoked by this method fails
ClassNotFoundException - if the class cannot be located

Source:-http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#forName%28java.lang.String%29

Is This Answer Correct ?    8 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is re-entrant. Is session beans reentrant. Is entity beans reentrant?

589


What is the purpose of the finally clause of a try-catch-finally statement?

570


What is a session? Can you share a session object between different theads?

560


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

583


What is a modular application? What does module-relative mean?

552






What’s jboss cache in short?

613


Explain about RMI Architecture?

619


Explain the difference between object state and behavior?

578


Which are the different segments of memory?

607


Will the general public have access to the infobus apis?

536


What restrictions are placed on the location of a package statement within a source code file?

624


Explain ioc concept?

630


Can I map more than one table in a cmp?

602


What if the static modifier is removed from the signature of the main method?

713


Why is string immutable in java?

588