Java char and byte are two basic types that are very simple. Java programming is very common, but not very common. Some Java programmers still do not really understand byte and char. Let's review it today.
Byte: byte, which occupies 8-bit binary data. The maximum number that can be expressed is the 8 power of 2, with positive and negative values. Therefore, the value range is-128... 0... 127.
CHAR: single character type. Java uses unicode encoding to represent a single character. Unicode occupies 2 bytes (16 bits ).
Char can represent any character, including letters and numbers, and Chinese characters.
For example, char C1 = 'a ';
Char C2 = '1 ';
Char C3 = 'I ';
Because the half-width characters are special, they come from 8-bit (1 byte) ASCII code, that is, 1 byte is enough to store. In Unicode, 8-bit low (1 byte) can be used to indicate that 8-bit high does not matter. Only one byte is occupied in the memory.
Chinese uses the complete 16-bit Unicode, which occupies 2 bytes in the memory.
Java's string is actually the encapsulation type of char []