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 is reflection in java?

1 Answers  


What is persistence xml in java?

1 Answers  


Explain the Sequence Diagram?

2 Answers   HCL,


What is meant by framework in java?

1 Answers  


How do I run a java project in netbeans?

1 Answers  


What is transactional in java?

1 Answers  


What is lambda used for?

1 Answers  


What happens when you omit a brace or misspell one of the words, like public or

1 Answers  


What is the difference between Enumeration and Iteration interfaces? What is the way of to retreive the objects from these interfaces ?

1 Answers   Cap Gemini,


Which version of jdk is required for netbeans 8.0 2?

1 Answers  


Who created eclipse?

1 Answers  


What is the content reside in Use case Document?

1 Answers  


Categories