I'm just starting with Java and trying to understand the basic concepts. I was asked the question, "Does Java use the one byte long ASCII Code set for character representation?"
I know that Java uses Unicode which includes ASCII, but is ASCII one byte long?
ASCII is a 7-bit representation, so yes, every ASCII character can fit in a byte
.
However, a Java char
is 16 bits. It's a UTF-16 code unit. So if you have a char
array of 100 characters, that will require 200 bytes (plus object overhead) even if every character is only ASCII. From section 3.1 of the JLS:
The Java programming language represents text in sequences of 16-bit code units, using the UTF-16 encoding.
See more on this question at Stackoverflow