In C + +
In C + +,char is the underlying data type, 8 bits, 1 bytes . Byte is not the underlying data type, generally a typedef unsigned char byte; in other words, byte is actually a unsigned char type, then it is also 8 bits, 1 bytes. The difference is that char can represent a range of-128-127, and a byte can represent a range of 0-255.
In Java
In Java,Char and Byte are the underlying data types , where the char type in byte and C + + is the same, 8-bit, 1-byte, 128-127. However, the char type is 16 bits, 2 bytes, ' \u0000 '-' \uffff '.
Why is a char in Java 2 bytes? inside Java is Unicode, so char in Java is 2 bytes , Java is actually supporting the Chinese variable name.
Add:
In C + +, the number of bits and bytes of some data is related to the machine operating system, hardware, and so on.
In Java, the operating system, hardware-independent, because Java is running on the virtual machine, so the data size is fixed.
By the way, long in Java is fixed at 8 bytes, 64 bits; int is 4 bytes, 32 bits.
Char in Java is different from Char in C + +