Java problem solving

java (jdk1.8) execute cmd command --->error: the main class cannot be found or cannot be loaded --->result result is Chinese garbled


First compile and generate a .class bytecode file through javac Hello.java (cmd runs in the same directory as the java file)

Run with java Hello, an error occurs: the main class cannot be found or cannot be loaded

Confirm that it is not the configured environment or errors caused by code syntax

I went to Baidu on the Internet and saw that it was the first part of the classpath environment variable. It must be added.; After adding it, an error still appears

I also saw that classpath is not needed for jdk6 and above. After deleting directly, you must close cmd and reopen it. The
compilation is successful, but the output of Chinese is garbled. The
source code is as follows:
Insert picture description here
output
Insert picture description here

Save the java file as an ANSI encoding method. The
Insert picture description here
solution is successfully solved, but it needs to be saved every time.

Furthermore, there is no need to modify the encoding of the file.
Baidu (https://blog.csdn.net/weixin_41557291/article/details/79711929) finds a solution. When compiling the .class file in the first step, specify the encoding method
Insert picture description here
Chinese garbled Solved, but every time you compile, you have to add a compilation method, and then configure an environment variable for convenience.
Right-click on My Computer—Properties—Advanced System Settings—Environment Variables—System Variables—New
Variable Name JAVA_TOOL_OPTIONS, the value is -Dfile.encoding=UTF-8, you
Insert picture description here
must rerun cmd
Insert picture description here

Guess you like

Origin blog.csdn.net/ExceptionCoder/article/details/107003327