This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Static Variables Vs Performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static Variables Vs Performance" Watch "Static Variables Vs Performance" New topic

Static Variables Vs Performance

Harnoor Singh
Ranch Hand

Joined: Aug 24, 2010
Posts: 35

I am designing one application which reads one file and do lots of processing before displaying to user. While designing application, I decided so keep lots of variables as static so that I need to peform processing logic only once and same variables can be used at number of places. One of my fried said that it is not good idea to declare variables as static as it is against principle of OOP. Can any one please tell if he is right ? Because if he is right than performace of my software will decrease because every time I need to use variables, i will first have to process the recornds and then dispaly to user. Please guide.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60800

Performance is not a good excuse for poor design -- especially when the performance issues are specious. Have you verified that performance is actually an issue when the program is properly designed?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Matthew Brown

Joined: Apr 06, 2010
Posts: 4344

Following OO principles and not misusing static variables does't mean you can't store the processed records. It just means using objects to store your data. So there's no reason the performance should be affected.
I agree. Here's the link:
subject: Static Variables Vs Performance
Similar Threads
static final variables
Two instances sharing memory ?
general GUI design question
EJB variable intialization
servlet and thread synchronization