You must create all objects
After you have created Reference, you have to connect to the new object. In general, use the new key to do this, the keyword NEW means, "Give me a new type of object." So in the above routine, you can use: string s = new String ("ASDF"); it is not public to "create a new String", and use string parameters to tell it "How to" make this String. Of course, String is not unique, Java programming is basically created class.
Where is the data exist?
How to expand how the part of the program is run-especially how the memory is allocated, and it is still necessary for a Tight description. Data can be stored in six places:
1, register (registers): This is the fastest storage because it is in place, in the processor. However, the number of registers is very limited, so it is assigned by the compiler. You don't directly control the registers, even the evidence it exists.
2, Stack: In the "General Random-Access Memory Area", the processor can directly access it through a stack pointer. The stack pointer is moved down to create a new storage, and the memory space is released. This is second only to the fastest and most efficient allocation of the register. Since the Java compiler must generate a code that controls the movement and downward movement of the stack pointer, the size and life cycle of the data that will be stored in the stack must be known when the program is compiled. This makes the flexibility of the program limit, so although Java stores some data - especially the object's Reference in the stack, the object itself is not placed in the stack.
3, Heap: This is a "multi-purpose memory pool" (General-Purpose Pool of Memory, also in memory), all Java objects are saved here. In the same stamp, the advantage of the heap is that when allocating space, the compiler does not need to know how much space allocation, or how long these data will stay in the stack. Therefore, the space used will be flexible. As long as you want to create an object, use New, you will allocate space in the stack when the program is executed. Of course, you have to pay for this flexibility, allocating the stack of storage spaces to be slower than the distribution stack (if you can create objects in the stack like C )
4, Static Storage: "Static" here means "in fixed position" (although it is still in RAM), the data in static storage can be accessed throughout the program. You can use Static keywords to indicate an element in the object, but the Java object itself will never be placed in static storage.
5. Constant Storage: The constant value is usually placed directly in the program so that they will not be changed, so safer. Sometimes constant can set the boundaries for yourself, so in the embedded system, you can choose whether it will put them in the ROM.