[Windows] Java code is garbled

The problem that Java code is garbled when executed at the Windows command prompt. There are two ways to do it, so I will introduce it !! 471c1995a62dc4b007e3ab8e72e6e08c[1].png

Why it happens

It seems that the character settings of the text editor and the command prompt are different.

At the bottom of the "Options" tag in the command prompt properties, The current code page is 932 Shift-JIS. However, when I look at Encoding from the VScode settings, it is ʻurf8`, so it may have been garbled because it does not fit. So this time I will set it according to VS code.

Premise

--People programming on Windows --Java beginner --I'm using VScode.

Solution 1 Use the CHCP command

The CHCP command is a command that can be used to set the character code. You can change it by specifying chcp <code page number>, and the command prompt setting will also change.

If you want to use the same UTF-8 as VScode, type chcp 65001 at the command prompt to switch the screen. After that, if you compile as usual and the characters are not garbled after execution, it is successful!

javac Sample1.java
java Sample1
Hello, Java!

Solution 2 Add options

How to run with command line options. This is fine, but for those who are tired of attaching it, the above method is good!

javac Sample1.java -J-Dfile.encoding=UTF-8
java Sample1 -J-Dfile.encoding=UTF-8
Hello, Java!

Reference site

When I execute java code, it becomes characters Windows command prompt character code setting Character code settings

Recommended Posts

[Windows] Java code is garbled
Script Java code
Java code TIPS
What is java
Java sample code 02
Java sample code 03
[Windows] Java code is garbled
When SimpleDateFormat is garbled like ٢٠١٨١٠٠٤٠٨٣١٣٣٦٥٧
Java sample code 04
What is Java <>?
What is Java
Java sample code 01
Java character code
What is Java Encapsulation?
What is Java technology?
What is Java API-java
[Java] What is flatMap?
[Java] What is JavaBeans?
[Java] What is ArrayList?
Java11: Run Java code in a single file as is
What is Java Assertion? Summary.
Digital signature sample code (JAVA)
Java parallelization code sample collection
Change java encoding in windows
Java test code method collection
What is a Java collection?
Java in Visual Studio Code
Write Java8-like code in Java8
[Java] What is jaee j2ee?
[Java] What is class inheritance?
When SimpleDateFormat is garbled like ٢٠١٨١٠٠٤٠٨٣١٣٣٦٥٧
Zip compression with Java in Windows environment without garbled characters
[Java] Code that is hard to notice but terribly slow
Until the code is executed
[Java basics] What is Class?
What is java escape analysis?
Java is the 5th day
What is JVM (Java Virtual Machine)?
Which Java HTTP client is better?
Guess the character code in Java
Code Java from Emacs with Eclim
Java Spring environment in vs Code
[Java] How to update Java on Windows
Where is the Java LocalDateTime.now () timezone?
Java 15 implementation and VS Code preferences
How slow is a Java Scanner?
Is Java on AWS Lambda slow?
Java 9 new features and sample code
Java build with mac vs code
Arbitrary string creation code by Java
Java environment variable settings (Windows, AdoptOpenJDK11)
Execute packaged Java code with commands
What is thread safe (with Java)
Java source code reading java.lang.Math class
JavaOne is now Oracle Code One
[Java] What is Concurrent Modification Exception?
[Java] Boilerplate code elimination using Lombok 2
Java Calendar is not a singleton.
What is a lambda expression (Java)
Java development environment (Mac, VS Code)
[Android] Convert Android Java code to Kotlin
Install Java 9 on windows 10 and CentOS 7