aspose file tools*
The moose likes Beginning Java and the fly likes Does classloader load all the code at start up? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does classloader load all the code at start up?" Watch "Does classloader load all the code at start up?" New topic
Author

Does classloader load all the code at start up?

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
I have a base class that has over 100 methods in it. Other classes extend this base class. Each sub-class however only uses a few methods of the base class. I know this is not a good design and maybe I should use composition instead inheritance. But does this kind of design affect performance? Does the classloader load all the 100 methods even only a few are called at run time?
Thanks.


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi Bruce,
as far as my knowledge goes, when a class is loaded for the first time then the whole byte code is loaded...
its not like shared libraries you know...
i say this because i tried my own classloader once (coded from some book) where i was just getting bytes of the classes upon loading and use defineClass() of ClassLoader...
regards
maulin
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Interesting.
This means it is not a good idea to extend a big class if I don't use many or all of the methods in that class.
Is this correct?
How can I verify this in a java program.
Thanks.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
well,
what i think is,
if you have a parent class which is really having all the methods worth declaring public/protected so that they can be extended by other utility classess then you can think of redesigning in such a way that you don't have so many methods in one class and group them somehow...
OR
the methods you are not using are such that you don't really need to make them inheritable then you can just make them private and then provide a placeholder in child to somehow call that method ('m not sure how we will go about this if we need to but if we have system in front of us then i guess i would be able to provide more fruitful input on this)...
OR
u can make an abstract class instead of a big parent class then leave methods empty and then create two subclasses (one will be the current parent class impl and the other will be the current child impl)...
these is all out of my empty mind on the weekends...but the essential thing i think is to "reconsider the design you have" in this case...
regards
maulin
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Thanks for the suggestions.
I try to convince my friend that big base class containing many unused methods is not a good practice. But I have to convince myself first. I want to make an example that can demo this. I will try to think hard tomorrow.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does classloader load all the code at start up?