我就不相信这个问题,始终无法弄明白。。

解决方案 »

  1.   

    天呐,这个对你Java有什么帮助吗?你知道在内存里不就行了。你干吗要较劲呢...我有点不解...
      

  2.   

    内存区域 一般被分为 4个部分 ,数据段,代码段,堆,栈,数据段也就是通常所说的的静态存储区域,所以呢,static 一般是存储在数据段的,另外堆是用来存储需要动态分配空间的变量,通俗的说就是new出来的。而栈呢就是存储我们通常所说的局部变量,嘿嘿,这个是一个高手给我讲的,不对的请指出来哦,谢谢拉
      

  3.   

    在我的另一贴里,好多高手,说:1。JAVA没有静态存储区。
    另一说:JAVA的static数据存在栈里。
      

  4.   

    java没有静态数据区,static数据是在堆里。
    记住就行了,要证明的话自己去看虚拟机规范,去分析虚拟机的代码,别人说的未必是正确的。
    这个问题实在是无聊,Java 虚拟机规范那本书里面有介绍,运行时数据区一共几部分我也贴过了,不想再说。这个对你学习java基本没有什么意义
      

  5.   

    补充:
    我的说法可能是错误的。
    首先确定,java 没有静态数据区。还是按照jvm规范里的说法: 
    3.5 Runtime Data Areas
    几个部分:
    The pc Register,Java Virtual Machine Stacks,Heap,Method Area,Runtime Constant Pool,Native Method Stacks
    其次,static fields存在什么地方。
    jvm规范,里面只是在
    2.17.3 Linking: Verification, Preparation, and Resolution
    中讲到,Preparation involves creating the static fields for a class or interface and initializing such fields to the standard default values。
    问题是这里并没有介绍到底是在哪里创建了static fields,这里并没有介绍。
    然后再看《Inside the Java Virtual Machine>>这本书里的说法: 
    http://www.artima.com/insidejvm/ed2/jvm5.html
    In addition to the basic type information listed previously, the virtual machine must also store for each loaded type:    * The constant pool for the type
        * Field information
        * Method information
        * All class (static) variables declared in the type, except constants
        * A reference to class ClassLoader
        * A reference to class Class  Class VariablesClass variables are shared among all instances of a class and can be accessed even in the absence of any instance. These variables are associated with the class--not with instances of the class--so they are logically part of the class data in the method area. Before a Java virtual machine uses a class, it must allocate memory from the method area for each non-final class variable declared in the class
    Constants (class variables declared final) are not treated in the same way as non-final class variables. Every type that uses a final class variable gets a copy of the constant value in its own constant pool. As part of the constant pool, final class variables are stored in the method area--just like non-final class variables. But whereas non-final class variables are stored as part of the data for the type that declares them, final class variables are stored as part of the data for any type that uses them. 
    也就是说,这里认为static的数据是放在方法区里的.
    这里http://dave-robinson.net/tuning/jvm_details.html也有概括,当然说法同样来自上面这本书.另外,static变量保存在堆里的说法见: 
    http://topic.csdn.net/u/20080924/06/d4e0c8cf-72e4-40db-a839-c2794290ccf8.html中7楼axman的说法:
    ....
    private static int A=3; 在哪里?
    在堆里.
    在堆里的A.class这个对象创建时的字段.对于Class类来说,它的实例A.class中有一个非静态字段int A.
    因为它是Class类的一个实例的字段,所以被该Class类的实例A.class所表示的类的实例共同引用,对于A.class所表示的类的
    实例来说它们是静态的.
    ....
    我认为,从实现的角度来考虑,这是可行的,axman对java的虚拟机机制比较熟悉,做出这个判断我不知道他是推测还是能够证明.这个我就不知道如何去具体的分析了.
      

  6.   

    zhang 兄,另一贴,你回的也比较多。
    比较赞赏你的看法,可你的看法还是模糊。
      

  7.   

    JAVA 和C++最大的区别之一好像就是在这里
    C++有专门的静态存储区,JAVA 没有PS ,大一曾经问过老师,3个教授回答的答案完全不同了,然后他们给我的一致答复就是:细节的别去研究了
      

  8.   

    C++有专门的全局/静态变量存储区。首先全局变量是是Java中不存在的,而静态变量又分为普通的static修饰的变量和类中的static变量,而java只有类变量一种.再说C++可以通过地址把变量的内存信息打印出来,你可以分析出哪些地址是相邻的.但是java就没法看了.
    这些细节的确没有必要研究,有精力还是多弄点实际的项目和理解一些设计模式.
      

  9.   

    个人认为在栈中~
    但是,关于JAVA没有静态存储区一说
    《think in java》明确说
    程序运行时,数据可以保存到以下六个地方:
    寄存器 堆栈 堆 静态存储区 常数存储区 非RAM存储区
      

  10.   

    thinking in java中,只说有五个地方可以存储数据:寄存器,堆栈,堆,常量存储,非RAM存储