简体   繁体   中英

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, eg

Math.round()

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

Gath

堆的Permgen(永久代)区域...

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 (eg, 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)

类在PermGen空间(即堆)中加载

所有类都加载在PermGen空间中

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM