Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disadvantages of using static in java

 
Sambhavi Balasubramaniam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Sambhavi Balasubramaniam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve!
 
sehrish malik
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 602
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

static Methods are Death to Testability

Check it out,

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





 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for the healthy inputs...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic