·  JAVA – Syntax – Terms – ClassLoader

 

- Info:

  - MyClassLoader can find class FindMe.class in the same directory and display its methods.

 

- Procedure:

  - Create JAVA Console Application Test.java and FindMe.java.

 

    Test.java

    import java.lang.reflect.Method;

    

    class MyClassLoader extends ClassLoader{}

    

    public class Test {

      

      public static void main(String[] args) {

        try{

          MyClassLoader myLoader    = new MyClassLoader();

          Class         findMe      = myLoader.loadClass("FindMe");

          Method[]      methods     = findMe.getMethods();   

          String        methodName  = methods[0].getName();

          System.out.println("methodName="+methodName);

        }catch(Exception e){System.out.println(e.toString());}

      }   

      

    }

 

    FindMe.java

    class FindMe {

      public void sayHello() { System.out.println("Helo from FindMe"); } 

    }