File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Dynamic class loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Dynamic class loading" Watch "Dynamic class loading" New topic

Dynamic class loading

Hema Sukumar

Joined: Dec 22, 2000
Posts: 22
Hi ,
Can somebody throw some light on
Dynamic class loading and Dynamic Method loading ?
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Mr. Ted Neward has several papers about this topic. They are really in depth discussion, and his results might surprise many Java Gurus.
Read them if you are interested. They might be more than you're asking for.
Join our SCJD Study Group when certified


Joined: Feb 09, 2001
Posts: 6
Make a class with one method name "Add" with Two String arguments . And run the followng code and give runtime argument as your classname, it will invoke object for your class and call your "Add" method.

import java.lang.reflect.*;
class DynamicClass
public static void main(String[] args) throws Exception
String className = args[0];
Class c = Class.forName(className);
Object object = c.newInstance(); /* For Loading the Class Dynamically */

String s1 = new String("Java");
String s2 = new String("Dynamic Class");
Class param[] = {Class.forName("java.lang.String"), Class.forName("java.lang.String") };
Method m1 = c.getMethod("Add", param ); /* To call a Method 'Add' in that Class Dynamically */
Object paramObj[] = {s1,s2};
Object retObj = m1.invoke( object, paramObj );
I agree. Here's the link:
subject: Dynamic class loading
It's not a secret anymore!