This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
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

Static and Global variables

 
Raj Waters
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static variables
Is performance bottleneck OR performance enhancement?
Global vairables
Is performance bottleneck OR performance enhancement?
yup
- Raj
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to performance forum...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Waters:
Static variables
Is performance bottleneck OR performance enhancement?

It probably doesn't make enough of a difference to care about.
When would a static variable be exchangeable for a non-static one anyway???

Global vairables
Is performance bottleneck OR performance enhancement?

Again, it probably doesn't make a difference.
What is much more important is that global variables are a *design*/*maintenance* bottleneck. See http://c2.com/cgi/wiki?GlobalVariablesAreBad
 
Raj Waters
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ilja
The article about global variables was good. My concern is:
Can it be related with performance?
I guess if you have too many global variables, the program performance is relatively good.
I mean I am not sure whether it logical to relate performance with global variables
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Waters:
My concern is:
Can it be related with performance?
I guess if you have too many global variables, the program performance is relatively good.

Why would that be?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what's a "global variable" anyway? Java doesn't really have them. Are you talking about static variables (compared to instance variables), instance variables (compared to local variables or parameters), or what?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood them to be "public static" - it's as global as a variable can get in Java. Might be wrong, of course... :roll:
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, but since he also asks about static as a separate question, I thought it best to ask.
 
Raj Waters
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets start with public static variables.
Lets say in our application we have some public static variables declared to be used globally. These variables can be referenced using the class names and can be done so by all the components of an application, Now:
Does it mean that the application can perform relatively fast if it has to access such static variables than instance variables.
i.e. if these variables are redefined as instance variables, will it make a difference.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic