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

Is the session factory thread safe?

697


What are the difference between RMI and CORBA?

627


What is a policy?

1788


What is the relationship between local interfaces and container-managed relationships?

602


Is it possible to stop the execution of a method before completion in a sessionbean?

613






How to implement dphibernate to activate lazy loading in Flex with java ?thanx in advance!

2570


What is the map interface?

624


whats is mean by tiles in struts

1640


What’s jboss jbpm?

595


Do we need to override service() method

1154


What is TL and its use?

2005


What is the diffrence between a local-tx-datasource and a xa-datasource?

596


Why use a datasource when you can directly specify a connection details? (in a J2EE application)

3476


what are the activation groupworks?

1687


What is RMI and what are the services in RMI?

619