File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes static variables - kept on Heap or Stack Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static variables - kept on Heap or Stack" Watch "static variables - kept on Heap or Stack" New topic

static variables - kept on Heap or Stack

jim gemlo

Joined: Feb 24, 2004
Posts: 20
Ok Instance variables are kept with their objects on the Heap but what about static instance variables? Where are they kept? Since there is one variable per class regardless of how many objects are created, are they stored outside of the object on the heap or are they put on the stack?
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
See this post with a very erudite answer from Ernest.

The short answer is, it depends. It's not the stack. It may be the heap, but technically it can't be. It's in some memory that the JVM has access to that isn't the heap. That's what I understood. Oh, and it doesn't matter.

I agree. Here's the link:
subject: static variables - kept on Heap or Stack
It's not a secret anymore!