Hi , Can somebody throw some light on Dynamic class loading and Dynamic Method loading ? Thanks, Hema
Roseanne Zhang
Ranch Hand
Joined: Nov 14, 2000
Posts: 1953
posted
0
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. http://www.javageeks.com/~tneward/ Thanks! Roseanne Join our SCJD Study Group when certified
vsshiva
Greenhorn
Joined: Feb 09, 2001
Posts: 6
posted
0
Hi, 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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.