Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static and Dynamic class loading

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know the difference between Static class loading and Dynamic class loading.
In general,we always use Static class loading only.Can anyone tell, under which situations we use Dynamic class loading??
 
krishnamoorthy kitcha
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj

See the link

http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html

Check and tell me about your feedback
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi krishna,
Thanks for providing this link.
I have gone through it,but still my original doubt is not clarified as to,when we use static class loaders and when dynamic class loaders??
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
moving this to the intermediate forum...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That article doesn't talk about "static" and "dynamic", and I'm not real sure what you mean. So I'm going to guess you mean the difference between knowing the class at compile time and knowing it at run time.

In the compile time option we specified ArrayList. The compiler has to have access to the ArrayList class to compile.

In the runtime example, we get the class name from a String. It might be ArrayList or it might be some new List implementation we've never heard of. The code compiles without knowing the exact class because we tell it we're pretty sure it's a List implementation when we do the casting.

We use the runtime trick (which I don't mind calling dynamic, though I don't think that's a dictionary definition) when we don't know the actual class at runtime. That lets us maybe change classes through configuration or lets users introduce new classes that we never know about by passing a new string. We never have to touch this code.

Does that answer the right question?
[ September 25, 2007: Message edited by: Stan James ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic