• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Disadvantages of using static in java

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .............
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

static Methods are Death to Testability

Check it out,

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





 
Marshal
Posts: 76059
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for the healthy inputs...

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic