Coding issues during Java compilation and running

Source: Internet
Author: User
First of all, Java's Chinese problems occur in many occasions. Use different processing methods for each scenario. You want to find out
Chu is "in Java Source code The problem of "running-time display of Chinese Characters in constant string quotation marks in the file"
.
OK, let's take a look at how javac compiles the string. First, the javac command line is useless-encod
The ing parameter specifies a character set. If not, the character set specified in the system environment is used. Next, javac starts to explain the source.
Code file, when encountering multi-byte characters, it will be interpreted using the character set encoding identified above, and converted to Unicode, written
In the. Class bytecode file.
Okay. Now we have to run this class file. After JVM is started, it will read the class bytecode and the Chinese strings.
All are represented in Unicode. There is nothing to say, and everything is the same (platform-independent ). This word may be output below
String to other applications Program Now: the console, file, socket, and so on... in this way, the JVM must first check the operating system.
(Note that the JVM does not know the encoding of these strings from the bytecode. They are all Unicode.
), And then follow the encoding to explain the Unicode code to the operating system's encoding. Of course, for special rings
The environment JVM may not check the operating system's encoding, but read from the environment variables, so that you can control the JVM
The purpose of the execution is encoding.
In the last step, if your operating system (or purpose) encoding is consistent with the real encoding (or has a compatibility relationship ),
), Then you will see the correct string. If you are inconsistent, what will you see? By the way, it is a question mark.

So "in the Linux operating system is ISO-8859-1" is not correct, the key is how to set the environment variable Lang
And whether the-encoding parameter is explicitly used.

In fact, if you compile and run on the same operating system, the output will never be faulty. That
Why did your fourth question come about? Very simple. The output string is 100% correct during virtual machine running,
Unfortunately, your Linux system does not support Chinese display, so you see garbled characters (not question marks, question marks mean you have encountered
From Remote logon, these codes are correctly displayed because your remote system has
Chinese display is supported.

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.