my dog learned polymorphism*
The moose likes Java in General and the fly likes why is it said that too many static methods are not good for performance. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why is it said that too many static methods are not good for performance." Watch "why is it said that too many static methods are not good for performance." New topic
Author

why is it said that too many static methods are not good for performance.

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 541
I have read that that too many static methods are not good for performance. Why should be avoid keeping to many static methods in code.

thanks..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39541
    
  27
Where did you read that? Was there no explanation? It is certainly bad OOP style.


Ping & DNS - updated with new look and Ping home screen widget
Tyson Lindner
Ranch Hand

Joined: May 16, 2012
Posts: 135
Monica. Shiralkar wrote:I have read that that too many static methods are not good for performance. Why should be avoid keeping to many static methods in code.

thanks..


Maybe what was meant was that if you have a large formula its not as efficient to break that formula's parts down into static methods as it is to just try and get it all done within one method. If you use several methods you'll have an extra cost of unnecessary references.

For static methods as opposed to instance methods, if anything it seems like static methods should be more efficient since they don't involve cost associated with the creation of an object.

Side question:
A program has 30 unused static methods and 1 used method, while another program only has the used method. Will the second program *run* faster than the first? My guess is no, the second program might compile some insignificant time faster, but its run time will be the same.



Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 541
thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36464
    
  15
Static methods have nothing to do with performance. They have to do with not using instance members.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7032
    
  16

Monica. Shiralkar wrote:I have read that that too many static methods are not good for performance. Why should be avoid keeping to many static methods in code.

The second question is much more important than the first because - especially at this stage - the last thing that should be on your mind is performance.

Basically, static methods are restrictive because they can only access other static methods and fields; and static fields - especially variables - are usually a BAD thing. Instance methods, OTOH, can access anything they can see.

This is just one of the reasons why MainIsAPain (←click).

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 541
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why is it said that too many static methods are not good for performance.
 
Similar Threads
using static methods
Static and Global variables
Session Listener
Static vs instance methods
Calling static method [ Object vs Class ]