+ 2

Why Char size is 2 Byte in Java ? while it take 1 byte in C

Please Explain

14th Jan 2020, 6:33 PM
Paras Jain
5 odpowiedzi
+ 13
Bit complicated. Computers only know numbers, humans only know text. So we need a way to turn text into numbers and the other way around. These days we do so with unicode, and java uses two bytes per char so it can store a single unicode UTF-16 codepoint. Before unicode there was ASCII/ISO-8859/Windows-1252. They used one byte per character. That means there are only 256 possible characters, which is enough for the latin alphabet, but not enough for japanese and russian and emoji. And that's what C calls `char`. Java does have a 1 byte-datatype called `byte`. C does have multiple-byte characters called `wchar_t`.
14th Jan 2020, 6:52 PM
Schindlabua
Schindlabua - avatar
+ 6
Because java is unicode based and c is ASCII code based and java contains 18 languages whereas c contains only 256 character. 256 is represented in 1 byte but 65535 can't represent in 1 byte so java char size is 2 byte or c char size is 1 byte.
10th Mar 2020, 6:35 AM
Ketul Patel
Ketul Patel - avatar
+ 4
Java supports unicode characters which covers the letters from a lot of international languages and hence the size required is 2 bytes whereas in C the ASCII characters just include the english language letters which pretty much fits within 1 byte. There is something with character encoding as well that I do not remember.
14th Jan 2020, 6:49 PM
Avinesh
Avinesh - avatar
+ 2
Java support more than 18 international languages so java take 2 byte for characters, because for 18 international language 1 byte of memory is not sufficient for storing all characters and symbols present in 18 languages. Java supports Unicode but c support ascii code. In ascii code only English language are present, so for storing all English latter and symbols 1 byte is sufficient (in C).
14th Jan 2020, 6:48 PM
Roman Ignatev
Roman Ignatev - avatar
0
Because java is unicode based and c is ASCII code based and java contains 18 languages whereas c contains only 256 character. 256 is represented in 1 byte but 65535 can't represent in 1 byte so java char size is 2 byte or c char size is 1 byte.
22nd Nov 2023, 8:19 PM
Shraddha suman Barik
Shraddha suman Barik - avatar