my dog learned polymorphism*
The moose likes Beginning Java and the fly likes where are static variables kept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "where are static variables kept" Watch "where are static variables kept" New topic
Author

where are static variables kept

Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110
Hello,

I know that local variables are kept in the stack. The instance variables are kept in the heap. I just wanted to know

1. where the static variables are kept.
2. where is the .class file loaded. It must be in the same memory area as the java runtime but do we have any particualr name for place where .class files are loaded.

regards,
vijay.
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
Originally posted by Vijay Raj:

1. where the static variables are kept.

In the heap itself. Static variables are stored only once, no matter how many objects are created

Originally posted by Vijay Raj:

2. where is the .class file loaded. It must be in the same memory area as the java runtime but do we have any particualr name for place where .class files are loaded.


Again in the heap memory. Everything is stored in the Heap itself.

The below text from Wikipedia might help:

When an object from the MyObject class is created for the first time. The JVM searches the file system for the definition of the class. The CLASSPATH environment variable contains locations where Java classes are stored. The JVM is looking for the 'MyObject.class' file. Depending on which package the class belongs to, the package name will be translated to a directory path.

When the 'MyObject.class' file is found, the JVM's class loader loads the class in memory. The JVM stores the code in memory, allocates memory for the static variables, and executes any static initialize block. Memory is not allocated for the object member variables at this point, memory will be allocated for them when an instance of the class, an object, is created


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
Thanks.
[ July 23, 2006: Message edited by: Aum Tao ]

SCJP 1.4 85%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where are static variables kept
 
Similar Threads
Code and Data segment.
Static variables
Class reference
y this code dosnt throw exception?
Memory issue between implements and extends