File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Disadvantages of using static in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Disadvantages of using static in java" Watch "Disadvantages of using static in java" New topic
Author

Disadvantages of using static in java

Sambhavi Balasubramaniam
Greenhorn

Joined: Mar 05, 2009
Posts: 7
Hi all,

I have a clarification. I have a program which has enormous usage of static variables and methods. Will there be any performance hit due to usage of static ? ANy help would be appreciated.

Cheers,
Sambhavi
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
There shouldn't be a performance hit. The bigger problem is unless they are simple utility methods then the design is probably poor. Minor things like static vs non-static rarely affect performance in a noticeable manner. Poor design, and IO usually dominate. As always don't guess, measure!


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Sambhavi Balasubramaniam
Greenhorn

Joined: Mar 05, 2009
Posts: 7
Thanks Steve!
sehrish malik
Greenhorn

Joined: Apr 13, 2009
Posts: 1
i have read from a book tht static mathods can call only static mathods thn how in main we can call other mathods which are not static .............
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 570
    
    7

Sehrish,

Please don't hijack threads - please start a new one so that others that have the same or similar question can easily reference.

Also, i would suggest that re-read that passage in your book. Still have questions - post another thread or you can search here - i would expect that this question has been asked before.

-steve
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449


static Methods are Death to Testability

Check it out,

http://java.dzone.com/articles/static-methods-are-death-testa






http://muhammadkhojaye.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39390
    
  28
That article is difficult to understand, but it suggests that using static methods is equivalent to procedural programming. Probably an exaggeration, but I see their point.

Static methods operate without creating an object, so they are restricted in their usefulness. If you need access to an object, then you will find it easier with instance methods.
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Static methods are the author of the article's personal windmill. I would argue that they are more like cars: they can be dangerous when used incorrectly, but are safe when used correctly.

John.
Sambhavi Balasubramaniam
Greenhorn

Joined: Mar 05, 2009
Posts: 7
Thanks all for the healthy inputs...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disadvantages of using static in java