gath
gath

Reputation: 25452

Where do java class live?

I know Java objects, instance variables are created and live in the heap, while the local variables and object references are created and live in the stack.

What about the "class" itself where does it live?

Am asking this because when you create static variables you call them using the class name, e.g.

Math.round()

When Math class is created, where does it live in memory (heap or stack)

Gath

Upvotes: 2

Views: 964

Answers (5)

donnyton
donnyton

Reputation: 6054

You can read more about the Permanent Generation (where classes, methods, etc are stored) here:

http://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation

Note however, that when you call a static method Java is actually making an internal instance of the object behind the scenes, so you are really calling the method on a "behind-the-scenes" global instance of the object.

Upvotes: 0

Dead Programmer
Dead Programmer

Reputation: 12575

Java classes lives in Permanent Generation heap .Also the interned string pool is stored here.

Permanent Generation heap contains:

  • Methods of a class (including the bytecodes)
  • Names of the classes (in the form of an object that points to a string also in the permanent generation)
  • Constant pool information (data read from the class file, see chapter 4 of the JVM specification for all the details).
  • Object arrays and type arrays associated with a class (e.g., an object array containing references to methods).
  • Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance)
  • Information used for optimization by the compilers (JITs)

Upvotes: 2

Nirmal- thInk beYond
Nirmal- thInk beYond

Reputation: 12054

all classes are loaded in PermGen space

Upvotes: 0

developer
developer

Reputation: 9478

classes are loaded in PermGen space i.e Heap

Upvotes: 1

user41871
user41871

Reputation:

Permgen (permanent generation) region of the heap...

Upvotes: 4

Related Questions