This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic class loading

 
Hema Sukumar
Greenhorn
Posts: 22
  • 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
  • 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
  • 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 );
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic