Think_java Chapter 2 everything is an object (1)

Source: Internet
Author: User
(1) Each language has its own method for operating elements in the memory. Sometimes Program You must note the type of data to be processed. Whether you directly operate on elements or use some indirect representation based on special syntax (for example, pointers in C and C ++) to operate on objects;

(2) Everything in Java is simplified, and everything is an object. Therefore, you can use a single fixed syntax. The operation identifier is actually a reference of the object )... (3) there are five storage areas in the memory to store data: @ 1: Register: This is the fastest storage area, because it is located in another storage area-inside the processor. However, the number of registers is extremely limited, so registers are allocated as needed. You cannot directly control it, nor feel any signs of register in the Program (on the other hand, C and C ++ allow you to think about how the compiler recommends register allocation) @ 2: Stack: it is located in general-purpose RAM (Random Access Memory), but the stack pointer can be directly supported from where the processor is located. If the stack pointer moves down, new memory is allocated. If the stack pointer moves up, the memory is released. This is a fast and effective way to allocate memory, only in registers. When creating a program, the Java System must know all desired lifecycles stored in the stack so that the pointer can be moved up or down. This constraint limits the flexibility of the program. Although some java data is stored in the stack, especially the reference of objects, Java objects are not stored in it; @ 3: Heap: A general memory pool (also located in the ram zone) is used to store all Java objects. The advantages of this pool are: the compiler does not need to know how long the stored data will survive in the heap. Therefore, it is flexible to allocate storage in the heap. When you need an object, you only need to write a new line of simple Code When the code is executed, the storage is automatically allocated in the heap. Of course, this flexible allocation must pay the appropriate price: allocating and clearing with Heap Storage may take more time than allocating with stacks (if you can create an object in the stack like in C ++ in Java) @ 4: constant storage: constant values are usually directly stored in the program code. This is safe because they will never be changed. Sometimes, in an embedded system, the constant itself is isolated from other parts, so in this case, you can choose to put it in ROM (read-only memory. @ 5: Non-ram storage. If the data exists completely outside the program, it can not be any Confucius or of the program, and it also exists when the program is not running. Two basic columns are stream objects and persistent objects. In a stream object, the object is converted into a word throttling, which is usually sent to another machine. In persistent objects, objects are stored on disks, so they can remain in their own State even if the program is terminated. The trick of this storage method is to convert objects into things that can be stored on other media; when necessary, they can be restored to conventional, Ram-based objects. Java provides support for lightweight persistent calls, while mechanisms such as jsbd and hibernate provide more complex support for storing and reading object information in the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.