what is class.forname() and how it will be useful ?

Answer Posted / pradip

class.forname() is used to create an instance of a class on
the basis of the name in string format instead of doing new
Class. One of its use is in cases where you have some
generic (common) logic to call methods of some classes just
on the basis of the names of the class and the method. The
example of reflection shown below uses the logic.

Eg:
performAction(String className, String methodName) {
Class class = Class.forName(className);
MethodUtils.invokeMethod(class.newInstance, methodName,
null);
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by light weight and heavy weight components?

553


What is java util function?

515


how to write a program for sending mails between client and server

1553


What is the finalize method do?

597


What is the file extension for java?

605






What is meant by local variable and instance variable?

598


Does constructor creates the object ?

583


What do you mean by scope of variable?

484


How to sort elements in a parallel array in java?

504


What is private public protected in java?

572


What is the main method java?

532


What is a local, member and a class variable?

577


How to create a fecelet view?

555


Which data type is a class in java?

571


What is the purpose of a parameter?

527