Home > Java > javaTutorial > The difference between java bytes and characters

The difference between java bytes and characters

(*-*)浩
Release: 2019-12-04 09:49:12
Original
4066 people have browsed it

The difference between java bytes and characters

Byte (byte): It is the basic unit of data processing in computers. It is customary to use a capital B to represent it. 1B (byte, byte) = 8bit (bit)

Character (char): refers to letters, numbers, words and symbols used in computers. Depending on the character encoding format, the number of bytes corresponding to each character unit is different.

The relationship between bytes and characters                                                                                                                                               # They are symbols used by people for the convenience of recording. Characters are stored in bytes in computersCharacters are stored in bytes according to the encoding standard specified by the character set

Byte means byte, which is the basic data type in Java. The value range of the type is -128 to 127.

Usually when reading non-text files (such as pictures, sounds, executable files), you need to use byte arrays to save the contents of the files. When downloading files, you also use byte arrays for temporary storage. The buffer receives the file contents. Therefore, byte is essential in file operations. It is used whether writing or reading files. English letters and numbers are single-byte, but characters in natural languages ​​such as Chinese are multi-byte. One byte can only represent 255 characters, and it cannot be used to process so many natural languages ​​around the world, so multi-byte storage is definitely needed.

In the input and output of files, InputStream and OutputStream process byte streams, which means that everything is assumed to be binary bytes;

And Reader and Writer are character streams. , it involves the issue of character set;

According to the ANSI encoding standard, punctuation marks, numbers, and uppercase and lowercase letters all occupy one byte, and Chinese characters occupy 2 bytes.

According to the UNICODE standard, all characters occupy 2 bytes.

The above is the detailed content of The difference between java bytes and characters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template