JAVA memory structure and data type

JAVA memory structure

Memory is a temporary storage of data. Its storage speed is very fast, but it is temporary storage. It starts to store from startup, and all data is lost after power failure or shutdown. The life cycle of memory is power on and power off. It starts to calculate when power on, and there is nothing when power off. The advantages are fast storage speed and the disadvantages are easy to break. If you turn on the machine, there is no response at all. The screen is not lit and the keyboard and mouse are not lit. In this case, there is generally a problem with the memory module. The machine blue screen and instruction errors are caused by memory.

The data of the program is stored in memory, not on the hard disk, because the hard disk is not safe and can read data. But memory is different. It is not allowed to read memory data, and the speed is very fast, so our programs are stored in memory.

Memory is like a large area of land that has not started. If you want to plant some vegetables in this land, you can plant them, but don't plant them where others occupy. Memory is the same. You are allowed to access some things, but if this content is occupied by others, you are not allowed to occupy it again.

Our data is stored in memory. There are many data storage cells in memory. You can save them wherever you want. However, Java is not selective. The storage of Java is represented by a virtual machine.

Memory storage unit: the computer stores by bits, and bits (only 0 and 1) are the smallest storage unit. Byte (8 bits equals 1 byte) K (1024 bytes equals 1KB) m (1024k equals 1m) g (1024m equals 1g) t (1024g equals 1t) P (1024t equals 1P).

The data of the program should be stored in the memory, and the size must be selected for storage. It can't be said that small things can also be stored with large ones. For example, if you have a liter of water, it should be stored in the cup. If you have to store 10 raw water in a cup, it will overflow. The large one cannot be stored in a small container, and the small one cannot be stored in a large container, which is very wasteful. As shown in Figure 3.3:

Figure 3.3

Java data type

If our programming language data wants to be stored in memory, we must first select a storage size so that it will not be wasted. The so-called storage size is called data type. What is a data type? We need to store data in types. We need to choose an appropriate type for our data to store, so as not to waste data and storage size.

Java data types have their own storage sizes. If there are different types, you should find different data types to store. Therefore, if the program is to be stored in memory, it is necessary to select the appropriate data type to store.

Value type:

  1. Integer:

  2. Floating point (decimal):

  3. Character type:

  4. Boolean type:

Byte: 8 bits represent a byte, that is, it is composed of 8 zeros and 1. It can form 256 identifiers. What are 256 identifiers? It is the combination of 8 zeros and 1. It can combine 256 identifiers in total. The maximum number of 8 bits he can inherit is 255, because he starts from 0, 0 ~ 255. Therefore, 8 bits are composed of 8 zeros and 1, a total of 256 descriptions and 0 ~ 255 values. As shown in Figure 3.4:

4.png

Short: 16 bits, that is, it consists of 16 zeros and 1. It can form 65536 identifiers and 0 ~ 65535 values.

Int: 32 bits, that is, it consists of 32 zeros and 1. It can form 4294967296 identifiers and 0 ~ 4294967295 values.

Long: 64 bits, that is, there are 64 zeros and 1s. It can identify all values on the earth.

Float: 32 bits, consisting of 32 zeros and 1. The decimal can be accurate to about 6 digits.

Double: 64 bits, composed of 64 zeros and 1s, and the decimal can be accurate to about 15 digits.

Char: 16 bits, which is represented by the Classl character.

Boolean: the Id only has 0 and 1. It means false, true and false. It is used to judge.

The above is the JAVA memory structure and data type introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>