How to load a class programmatically?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a bean class?

654


What is predicate in lambda expression?

618


What services can invoke lambda?

641


How do I open the java console in windows 10?

727


What are struts java?

666


What is a service layer in java?

606


What about products that claim to block java applets at a firewall? : java security

710


How can I write a program that takes command line input?

662


What is the meaning of the words public, static and void?

636


Which interceptor is responsible for setting action javabean properties?

616


Can the main method be declared final?

720


What is use of jpa?

646


What is type_scroll_insensitive in java?

679


What is @override annotation in java?

672


Does ms edge support java?

620