File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic class loading

 
Hema Sukumar
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Can somebody throw some light on
Dynamic class loading and Dynamic Method loading ?
Thanks,
Hema
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic