Java memory structure
Memory is a temporary storage of data. Its storage speed is very fast, but it is a temporary storage. It starts from the start of power supply, and all data is lost after power supply or shutdown. The life cycle of memory is to turn on and shut down. When the computer is turned on, the calculation starts, and there is nothing left when the computer is turned off. Advantages have fast storage speed and disadvantages are easily broken. If it does not reflect at all when booting, the screen is not bright, the keyboard and mouse are not bright, and in this case, there are usually problems with the memory stick. The machine blue screen and instruction errors are all caused by memory.
The data of the program is stored in memory and is not stored on the hard disk because the hard disk is not safe and can read data. But the memory is different. It does not allow memory data to be read, 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 grow some vegetables in this land, you can plant them as you want, but don’t plant them in places occupied by others. The same is true for accessing some things that allow you to access, but if this content is occupied by others, it is not allowed to be occupied by you if you want to.
Our data is stored in memory. It is OK to store many data storage cells wherever they want, but Java is not selective, and Java storage is proxyed by a virtual machine.
Memory storage unit: The computer is stored bit by bit, and bits (the only storage can be 0 and 1) bits 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 must be stored in memory, and the size must be selected for storage. Things that cannot be said to be small must be stored in large quantities. For example, if you have a liter of water, you must store it in a cup. If you have 10 raw water you have to store in a cup, it will overflow. Large ones cannot be stored in small containers, and small ones cannot be stored in large containers, which is a waste. As shown in Figure 3.3:
Figure 3.3
Java data types
If our programming language data wants to be stored in memory, then we must first choose a storage size so that we will not waste it. The so-called storage size is called data type. What is a data type? We need to store data in types, and we need to choose a suitable type for our data to store so that we will not waste data or waste storage size.
Java data types have their own storage sizes. If there are different types, you need to find different data types to store. Therefore, if the program needs to be stored in memory, you must choose the appropriate data type to store it.
Numeric type:
1. Integer:
2. Floating point (decimal):
3. Character type:
4. Boolean type:
byte: 8 bits represent a byte, that is, there are 8 0s and 1s, which can form 256 identifiers. What are 256 logos? It is the combination of 8 0s and 1s, which can combine 256 signs in total. The largest number he can inherit is 255 because it starts from 0, 0~255. So 8 bits are composed of 8 0s and 1s, forming a total of 256 descriptions and 0~255 values. As shown in Figure 3.4:
4.png
short: 16 bits, that is, there are 16 0s and 1s, which can form 65536 identifiers, 0~65535 values.
int: 32 bits, that is, there are 32 0s and 1s, which can form 4294967296 identifiers, 0~4294967295 values.
long: 64 bits, that is, 64 0s and 1s are composed of which can identify all the values on the earth.
float: 32 bits, composed of 32 0s and 1s, and the decimal can be accurate to about 6 digits.
double: 64 bits, 64 0s and 1s, and the decimal can be accurate to about 15 digits.
char:16 bit, it is represented by ASCLL characters.
boolean: The logo has only 0 and 1, it is false true and true, used for judgment.
The above is the Java memory structure and data type introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!