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

How do I enable java in google chrome?

0 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,


What is cdi bean in java?

0 Answers  


How do I open the java control panel?

0 Answers  


What are the differences between java’s old java date api and java 8’s date and time api?

0 Answers  






What is the difference between Object Code and ByteCode? Why do people keep saying that bytecode is like the intermediate of source and object code? Also, which is better/commonly used and why? Please keep in mind that I am a beginner, please keep all terminology fairly simple. Thanks!

1 Answers  


What is aop in java?

0 Answers  


What is a cookie in java?

0 Answers  


Difference between Abstract Class & Interface?

4 Answers   HCL, IBM,


What are the types of cookies in java?

0 Answers  


What is the java api?

0 Answers  


What is custom tag in java?

0 Answers  


Categories