How to run Java with cmd command?

Avoid development tools, do you remember how to run java programs with cmd commands? In the process, where are easy to go wrong, let us review it~

1. First open a notepad
. Have you ever wondered why there are many text files similar to notepads, such as WordPad, Word, etc.? Why can't they be used for direct execution? (The answer is given later)
Insert picture description here

2. Change the file extension to .java

Insert picture description here

3. Enter cmd in the windows search to open the command prompt
Insert picture description here
4. Import the folder where the file is located

Insert picture description here

5.javac compiles the .java file to turn it into a bytecode .class file

Insert picture description here

Insert picture description here

6. Interpret the .class file

Successful operation: Insert picture description here
Summary:
Remember the above question? We can see the mistakes made in the two processes: if
Insert picture description here
Insert picture description here
there is a space, it can’t be executed. ↑Insert picture description here
Insert picture description here
Notepad can’t execute.

The answer to the question is: Because the compiling ability of these text files is very low, many formatted symbols will affect the file generation machine code and thus make it impossible to compile. However, files such as word and WordPad will have many formatting symbols, which will result in failure to compile normally, or it can be understood that Notepad is the cleanest text file without fancy formats such as spaces and line spacing.

Guess you like

Origin blog.csdn.net/Lamont_/article/details/114436058