It's not a secret anymore!
The moose likes Java in General and the fly likes Static and Dynamic class loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static and Dynamic class loading" Watch "Static and Dynamic class loading" New topic

Static and Dynamic class loading

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
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

Joined: Feb 04, 2006
Posts: 96
Hi Raj

See the link

Check and tell me about your feedback
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
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

Joined: Oct 14, 2002
Posts: 8898
moving this to the intermediate forum...

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Static and Dynamic class loading
It's not a secret anymore!