File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Where does static variables live? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Where does static variables live?" Watch "Where does static variables live?" New topic
Author

Where does static variables live?

William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
Hi,
Where do static variables (yes, they must be instance variables) live? As the book says, instance variables live IN the object on the heap, static variables are shared with all the objects of the very class, so where are they?


Java is better and better, yet bitter and bitter.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
On the heap, in the instance of the Class object created to represent the class when it gets loaded? Here I am assuming you are writing about the class variables. The objects referred to by those class variables (if they are reference variables) are just regular objects on the heap.
[ October 11, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
Thanks a lot, Barry.
And the Class object of a class must be a singleton, right?
Pavan Sambare
Greenhorn

Joined: Aug 21, 2006
Posts: 23
There is only one Class object for each class in the jvm. This Class Object is created by the ClassLoader when it is loading the class.


SCJP 1.4 -- 98%<br />SCWCD 5 -- 97%
 
Consider Paul's rocket mass heater.
 
subject: Where does static variables live?
 
Similar Threads
residence of static variable
static variables in multithreading
where do static variables live ?
regarding memory and doubt abt static
Where do static variables live