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 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

Disadvantages of using static in java

Sambhavi Balasubramaniam

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.

steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
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! - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Sambhavi Balasubramaniam

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

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

Joined: Sep 18, 2000
Posts: 601


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.

Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

static Methods are Death to Testability

Check it out,
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
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

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.

Sambhavi Balasubramaniam

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

I agree. Here's the link:
subject: Disadvantages of using static in java
It's not a secret anymore!