How to load a class programmatically?



How to load a class programmatically?..

Answer / madhu

public class MainClass {

public static void main(String[] args){

ClassLoader classLoader = MainClass.class.getClassLoader();

try {
Class aClass = classLoader.loadClass("com.tech.MyClass");
System.out.println("aClass.getName() = " + aClass.getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

}

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More Java Related AllOther Interview Questions

What type of parameter passing does java support?

0 Answers  


i have client interview in TCS.client is CITI BANK.how to face it,what type of questions they will ask,please tell send me to kumar525job@gmail.com

0 Answers   TCS,


Why bean class is used in java?

0 Answers  


What is dto layer in java?

0 Answers  


In an htm form i have a button which makes us to open another page in 15sec.how will you do that?

0 Answers  






What is difference between map and flatmap in java 8?

0 Answers  


What is the use of jprofiler?

0 Answers  


What is native api in java?

0 Answers  


What does persist mean in java?

0 Answers  


What is jep in java?

0 Answers  


What are messages in java?

0 Answers  


What is contextpath in java?

0 Answers  


Categories