Reflection to load a class

Hi, I am newbie to JAVA. Can anyone tell me how to use reflection to load a class and call a method on the created object through reflection API?
[159 byte] By [Basav1985a] at [2007-11-27 9:30:19]
# 1
By the way, thanks in advance, Basav
Basav1985a at 2007-7-12 22:41:23 > top of Java-index,Java Essentials,New To Java...
# 2

No. You're a newbie, you don't need to know about that, and if you did know about that I guarantee you you'd abuse it, it would distract you from learning the basics, and you wouldn't fully understand it anyway. Some other clown is guaranteed to tell you, but I implore you to ignore this feature for now, it will only hinder your learning process, and more importantly you won't have the skills to debug reflective code, which is notoriously awkward to do

Learn to walk before you try running. Even experienced developers badly screw things up using reflection

georgemca at 2007-7-12 22:41:23 > top of Java-index,Java Essentials,New To Java...
# 3
Thank you very much for the reply.But this is the exercise I have to do. I started learning JAVA since 15 days. Even if this is difficult, I ll try to grab whatever possible. Please gimme a very simple example or good links. Thanks again,Basav
Basav1985a at 2007-7-12 22:41:23 > top of Java-index,Java Essentials,New To Java...
# 4

> Thank you very much for the reply.

>

> But this is the exercise I have to do. I started

> learning JAVA since 15 days. Even if this is

> difficult, I ll try to grab whatever possible. Please

> gimme a very simple example or good links.

>

> Thanks again,

> Basav

Fair enough. Don't say I didn't warn you

Class clazz = Class.forName("com.mydomain.myapp.MyClass";

Object obj = clazz.newInstance();

Method performAction = clazz.getDeclaredMethod("doSomething", new Class[0] );

Object result = performAction.invoke(obj, new Object[0]);

Don't bother asking for any explanation of what it means, or for any help when it doesn't work. You've been coding a whole 15 days, you're obviously ready for this by now, and should know exactly what it's all about and how to fix any problems that arise

georgemca at 2007-7-12 22:41:23 > top of Java-index,Java Essentials,New To Java...
# 5
Thank you!!!
Basav1985a at 2007-7-12 22:41:23 > top of Java-index,Java Essentials,New To Java...
# 6

> Thank you!!!

Don't bother thanking me. Despite what you think, I haven't done you any favours. You're going to use this technique in wholly inappropriate places from now on, because it's shiny and fangled. You'll be back shortly asking 50 questions about what's going wrong, and the next guy will say "why are you using reflection for this?" and you won't be able to say

You really ought not to bother with this API yet

georgemca at 2007-7-12 22:41:23 > top of Java-index,Java Essentials,New To Java...