Java char and byte

Source: Internet
Author: User

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 []

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.