Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where are static variables kept

 
Vijay Raj
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
[ July 23, 2006: Message edited by: Aum Tao ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic