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
Difference between linkedlist and arraylist.
What is the range of the short type?
Explain naming conventions for packages?
what is interface in java? Explain
what is the difference between Object Based Language and Object Oriented Language?
Implementations of set interface?
What is the use of generics? When was it added to the Java development Kit?
What is a jit compiler?
What is a blocking method in Java?
What is runtime locatable code?
Can we convert integer to string in java?
What does split function do in java?
How garbage collection is done in java?
What is the static block?
What data type is string java?