File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Performance Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Performance Doubt" Watch "Performance Doubt" New topic

Performance Doubt

Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
Hey all,
I have a simple doubt regarding performance. Suppose i am having a common class which contains some common methods.
Now i need to use common methods in my specific class. Which way is better?
1) Extend the super class which contains common methods and there by we can just call those methods.
2) The commom class contains methods which are public static, so just call them by Class.methodname

Thanks & Regards,
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

As with every performance question: it depends on the context of how you are using these classes. If you want to find out, write both and prerformance test them.

However, performance should almost never be a condsideration when creating your static model. Design classes based on their function, not how they may perform.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Vijayendra V Rao
Ranch Hand

Joined: Jul 04, 2004
Posts: 195
The decision of extending a class should be based on whether the "specific" class that you are talking about would make any design sense by being made as a sub-class of the other class (which has those methods). However, if you are thinking of inheritance just in order to use those methods, then that would be just a "quick-and-dirty" inheritance. Simple thing...don't go for it because you yourself will get confused when you are trying to make sense out of the whole code at a later point (not to mention your fellow programmers ;-) )

If both the classes have no hierarchical sense, then go with the second method. If you have declared the methods to be static, then they will neither be stored in the heap nor the stack nor the constant storage...they go into a different type of storage, in the RAM, called "static storage". So I don't think this approach will be a hit on the performance.

Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
Hi Animesh,

In my experience, best perforances come from improved algorythms and rarely from "technical tricks". As a programmer, you want surely know more on how java compilers manage your code. However, don't expect too much time gain using this knowledge ;-)

Best regards,

Lionel Badiou
CodeFutures Software
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
Thanks all for the help
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Performance Doubt
jQuery in Action, 3rd edition