| 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: 852
|
|
|
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
Ranch Hand
Joined: Sep 18, 2000
Posts: 491
|
|
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: 341
|
|
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: 32654
|
|
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...
|
 |
 |
|
|
subject: Disadvantages of using static in java
|
|
|