Follow Our FB Page << >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

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

Answers were Sorted based on User's Feedback

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

Answer / amit singh

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
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
amit09mca(scjp 1.5 and manymore)

Is This Answer Correct ?    5 Yes 0 No

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

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.

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

Is This Answer Correct ?    3 Yes 0 No

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

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

Post New Answer

More Core Java Interview Questions

What is actual difference between statement,prepared statement and callable statement and when we have to use it? pls post a answer with code and clear explanation. thanks

2 Answers  

If a method is declared as protected, where may the method be accessed?

0 Answers  

What is difference between overloading and overriding?

2 Answers   Accenture,

Superclass of exception

4 Answers   Nous,

How GUI component handle its own events?

1 Answers  

What is the difference between throw and throws?

5 Answers   Cap Gemini,

What is wrapper class example?

0 Answers  

What are the access modifiers in java?

0 Answers  

In collection sorting comparable and comparator interface will be used..but why this two interfaces required..two will work same purpose so why there are two interfaces instead of one?when to use comparator and when to use comparable?

1 Answers   Ericsson,

What are invisible components?.

0 Answers  

Write a java program to get a string of words and print the numbers of each word count in descending order

11 Answers   Logica CMG, Subex,

Which is bigger float or double java?

0 Answers