In a nutshell primitive, object and class data are stored in 3 different memory areas: heap space, method area and native area. The heap space holds object data, the method area holds class code, and the native area holds references to the code and object data.
简单地说,对象和类的数据存储在3个不同的内存区域:堆区、方法区和本地区。 堆区持有对象数据,方法区持有类的代码,本地区持有代码和对象数据的引用。
The method area is also known as the permanent generation space (PermGen). All class data are loaded into this memory space. This includes the field and method data and the code for the methods and constructors.
All objects being instantiated during runtime are stored in the heap space. The heap space again is divided into several parts: eden, survivor, and old generation Space.
Method executions are within a thread. Local variables of primitive types and references are stored here. The references for example points to Objects like String stored in the Heap space
下面是一个实例:
public class HelloWorld {
private static Logger LOGGER = Logger.getLogger(HelloWorld.class.getName());
public void sayHello(String message){
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.YYYY");
String today = formatter.format(new Date());
LOGGER.info(today + ": " + message);
}
}
数据存储形式:
参考资料:
http://www.pointsoftware.ch/en/under-the-hood-runtime-data-areas-javas-memory-model/