File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Dynamic class loading" Watch "Dynamic class loading" New topic
Author

Dynamic class loading

Hema Sukumar
Greenhorn

Joined: Dec 22, 2000
Posts: 22
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
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
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://aspose.com/file-tools
 
subject: Dynamic class loading