• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Performance Doubt

 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
Animesh
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for the help
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic