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
What is one third plus one third as a fraction?
what is server side caching?
How do you classify Dialog Box?
Break statement can be used as labels in java?
What is the basic concept of java?
I want to print “hello” even before main is executed. How will you acheive that?
What are the topics in advance java?
Tell me a few examples of final classes defined in Java API?
Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?
Can list have duplicates in java?
Is array synchronized in java?
worst case complexities of Quick sort and Merge sort.
Does java runtime require a license?
Can we sort hashmap in java?
Is simpledateformat safe to use in the multithreaded program?