Char size in old languages like c/c++ is 1 byte .but if you talk about in java char size becomes 2 byte.can you elaborate why?
-
2Does this answer your question? [Why does the Java char primitive take up 2 bytes of memory?](https://stackoverflow.com/questions/3956734/why-does-the-java-char-primitive-take-up-2-bytes-of-memory) – sanjeevRm May 24 '21 at 16:04
-
Tip: For working with individual characters, learn to use the methods related to [code point](https://en.wikipedia.org/wiki/Code_point) integers, the number assigned by the Unicode Consortium to each of the 143,859 known characters. The `char` type is obsolete. – Basil Bourque May 24 '21 at 16:26
4 Answers
The char
data type in Java originally used for representing 16-bit Unicode. Therefore the size of the char data type in Java is 2 byte

- 1,541
- 2
- 13
- 24
Java uses UTF-16 encoding. C/C++ is using UTF-8.
8 and 16 are the number of bits here.

- 16,452
- 1
- 18
- 39
The evolution of Java was at the time when the Unicode standards had been defined for a very smaller character set. Java was designed for using Unicode Transformed Format (UTF)-16 when the UTF-16 was designed. The char
data type in Java is originally used for representing 16-bit Unicode. Therefore the size of the char data type in Java is 2 byte, and same for the C language is 1 byte. Hence Java uses Unicode standard.

- 52
- 1
- 4
Java follows the Unicode standards. Java was developed for worldwide interchange, processing, and display of the written texts of the diverse languages and technical disciplines whereas C and C++ not . So the char size for java is 2 bytes and that for C and C++ is 1 byte.

- 17
- 4