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

why is java not 100% oops?

5 Answers   IBM,


What is gwt in java?

0 Answers  


What is jpa implementation?

0 Answers  


What is a flatmap?

0 Answers  


How do I run a java program from the command line?

0 Answers  






What is entitymanager in jpa?

0 Answers  


Is lambda cheaper than ec2?

0 Answers  


Explain the Sequence Diagram?

2 Answers   HCL,


In java thread programming, which method is a must implementation for all threads?

0 Answers  


How many types of jdk are there?

0 Answers  


Why we need method overriding in JAVA ? I mean which method I have to override I can write that method in my Class.

1 Answers  


program A and B are analysed and found to have worst case running time greater than 150NlogN and N*N respectively. which program has the better guarantee after the running time for the large values of N(N>10000)? which program has the better guarantee for the running time of small program N (N<100)? which program will run faster on average for N=1000?

0 Answers   St. Pauls University,


Categories