what is class.forname() and how it will be useful ?
Answers were Sorted based on User's Feedback
it is useful when you don't know about the class as compile
time you must to use it you pass the class name as a string
and
its a part of reflection api
but you used it when you connect through db
and many more you should do when you don't know the class
at compile time
and also above which mention by pradip right
amitsingh200@gmail.com
amit09mca(scjp 1.5 and manymore)
| Is This Answer Correct ? | 5 Yes | 0 No |
Answer / 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 |
Answer / keerthi
In java we are using class.forName("classname")in jdbc
for creating instance of driverclass at the same to
registering with drivermanager.
| Is This Answer Correct ? | 2 Yes | 0 No |
What is the difference between compare and compareto in java?
What does function identity () do?
Can java inner class be static?
Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.
what is Remote Reference Layer ?
How arrays are stored in memory in java?
What is the generic function?
What is static block?
What is your platform’s default character encoding?
why to use transient variables when static variables can be used for Serialization
we r taking <load-on-startup>0</load-on-startup> <load-on-startup>1</load-on-startup> in deployment descripter for loading servlets like serv1 N serv2? so 'll it take serv1 or serv2
What does singleton mean in java?