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:
类在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.