search
HomeJavaJavaBaseSolution to garbled characters in java when running cmd

Solution to garbled characters in java when running cmd

The garbled characters when executing the java file in cmd are as follows: (Recommended: java video tutorial)

Solution to garbled characters in java when running cmd

Reason :

Since the JDK is an international version, when compiling, if we do not use the -encoding parameter to specify the encoding format of our JAVA source program, javac.exe will first get the default encoding used by our operating system. encoding format, that is, when compiling a java program, if we do not specify the encoding format of the source program file, JDK first obtains the file.encoding parameter of the operating system (it saves the default encoding format of the operating system, such as WIN2k, its The value is GBK), and then JDK converts our java source program from the file.encoding encoding format to the default UNICODE format within JAVA and puts it into memory.

Then, javac compiles the converted unicode format file into a .class class file. At this time, the .class file is UNICODE encoded, and it is temporarily placed in the memory. Then, JDK converts this file into a UNICODE file. The encoded and compiled class file is saved to our operating system to form the .class file we see.

For us, the .class file we finally obtained is a class file whose content is saved in UNICODE encoding format. It contains the Chinese string in our source program, but at this time it has been passed through file. The encoding format is converted to UNICODE format.

When we compile without setting, it is equivalent to using the parameters: javac -encoding gbk XX.java. Of course, incompatibility will occur.

Solution:

1. Convert to UTF-8 encoding format, but there are still errors

The solution is: you should use the -encoding parameter to specify the encoding method :javac -encoding UTF-8 XX.java

2. Start-->Computer-->Mouse reverse key (right mouse button)-->Properties-->Advanced system settings--> ;Environment variables-->System variables

New. Then enter: "JAVA_TOOL_OPTIONS" variable, the value is "-Dfile.encoding=UTF-8"

Then confirm, confirm, after confirmation. Open a new command line window and enter the javac command again.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Solution to garbled characters in java when running cmd. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)