Problems with Java encoding

Source: Internet
Author: User

< turn >

Since the JDK is an international version, at compile time, if we do not specify the encoding format of our Java source program with the-encoding parameter, Then Javac.exe first get our operating system by default encoding format, that is, when compiling Java programs, if we do not specify the source program file encoding format, the JDK first obtains the operating system's file.encoding parameter (it is the operating system default encoding format, such as Win2K, which has a value of GBK), then the JDK translates our Java source program into memory from the file.encoding encoded format into the Java internal default Unicode format. Javac then compiles the converted Unicode file into a. class file, at which point the. class file is Unicode encoded, which is temporarily placed in memory, followed by The JDK saves this compiled, Unicode-encoded class file into our operating system to form the. class file that we see. For us, the. class file that we finally get is the class file that the content is saved in Unicode encoded format, which contains the Chinese string inside our source program, except that it has been converted to Unicode format by file.encoding format. When we compile without setting, the equivalent of using parameters: Javac-encoding GBK Xx.java, of course, there will be incompatibilities.

The workaround is: You should use the-encoding parameter to indicate the encoding: javac-encoding UTF-8 Xx.java, this is not a warning, the operation is also correct in JCreator 4 settings: Menu: Configure--Options-- > JDK Tools--Compiler, check <default>, and then select Edit,parameters inside, first add:-encoding UTF-8.

How do I view the operating system character set?

Under Windows platform, enter the DOS window, type: CHCP
You can get the code page information for the operating system, and you can view the detailed character set information for the code page from the Language Options in Control Panel.

For example:

My Activity code page is: 936, and it has an encoding format of GBK.

Problems with Java encoding

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.