Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Class Loading?

Status
Not open for further replies.

JavaDude32

Programmer
Aug 25, 2001
180
0
0
US
Okay, as far as I understand the ClassLoader, it loads all classes at runtime. My project I am currently working on, may have about 50 to 60 classes when it is finished. The classes that are needed is dependent on user input, so I was wondering, (a) is Dynamic Class Loading in Java possible (such as gathering the classes that are needed once the program can determine which ones)? (b) If so, how is this accomplished and if I'm correct in thinking this will likely be a significant performance factor?

Thanks for any help,
JavaDude32
 
a) yes
b1) by writing your own ClassLoader
b2) could influence startup speed, but I would think creating and destroying instances of classes would affect performance more.

Unless you are really expert I would say, "Don't even go there!".

this article seems to have a lot of information.

Also, Reflection is a way of doing dynamic class loading programatically. This is more approachable, but uses resources more than the primordial class loader.

I forget the most important point....does the standard class loader load all of your classes immediately or on demand? Can anyone help me out here? Jeremy Nicholson, Director of a UK-based Java and Data Warehousing consultancy
 
Jeremy,

classes are loaded dynamically.

--

A prospective reason to use your own class loader is to load classes by "name". To dynamically extend an application without having to recompile and release a new version of the application.

Simply drop a new .class or .jar file in your file structure and add the name(s) of the new classes, and other relevant inforamtion, to the applications configuration. Of course the classes will implement one or more application supported interfaces otherwise they are not much use.

Does that make sense?

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top