Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
in java program where the static variables are stored
Posted
Updated 5-Jan-16 5:21am
v2
Comments
Sergey Alexandrovich Kryukov 5-Jan-16 11:35am    
What does it mean, where?
—SA

They are stored in some statically defined block of memory statically reserved by the moment when the application is loaded and is ready for execution; it's size is statically known to runtime system. That is, this is not stack and not heap. The implementation depends on the implementation of JVM and host OS.

Technically speaking, in some system, stack and static memory share the same memory unit, from the OS point of view, but logically/functionally they are still isolated, so what I said in the paragraph above is still true. Again, implementations can be different, but functional properties of this memory are the same.

I don't think the word "identify" in your question title makes sense. Perhaps you need to understand that static fields belong to the class itself, not to each individual instance. The object of a field is only one per class. Sometimes, such fields are called "class fields", as opposed to "instance fields".

Now, if a field type is of reference type, it should be obvious that only the reference object itself is stored in the static memory block, but the referenced object is on heap. Here, you need to understand that any object of reference type is represented by two objects in memory: the reference part (analog to pointer in native memory systems) and referenced part.

—SA
 
Share this answer
 
v3
Comments
Maciej Los 5-Jan-16 11:57am    
5ed!
Sergey Alexandrovich Kryukov 5-Jan-16 13:20pm    
Thank you, Maciej.
—SA
Maciej Los 5-Jan-16 14:08pm    
First time i see so frugal form of reply ;)
Sergey Alexandrovich Kryukov 5-Jan-16 14:10pm    
It was a funny slip of a hand, sorry. But I hope you've been able to understand what I meant to say. :-)
And I hope, even before a fix, it was a true statement. :-)
—SA
Maciej Los 6-Jan-16 8:21am    
;)
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search gave nearly a million hits: java program where the static variables are stored - Google Search[^]
The top answer is pretty complete: Where are static variables stored in java? - Stack Overflow[^]

In future, please try to do at least basic research yourself, and not waste your time or ours.
 
Share this answer
 
Comments
Maciej Los 5-Jan-16 11:57am    
5ed!
Static variables in C are stored in the data segment of the program's memory. This segment is further divided into two parts: initialized data segment (also known as data segment) and uninitialized data segment (also known as BSS segment).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900