Command window implements Java code
First: use a txt or download a notepad++, write java code in text, and then run it in the cmd window.
public class HelloWorld{
public static void main(String[] args){
System.out.println("HelloWorld!");
}
}
one:
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly
2:
This enters the cmd command window!
**javac: ** Generate class files:
But you will find that there is a problem: what I wrote is obviously HelloWorld! , How did it become hello, world! , This is because there is a problem with my class save path. Generally speaking, in our projects, src files have their own copyrights, and the delivered files are generally classes. Of course, there is javaDoc behind, so I won’t explain it here.
The src in the code is the folder where I save the notepad++ file, this can be placed anywhere. The class folder is used to save **. class files, it is conceivable that my javac** is problematic. But the reason why it can run is because I have HelloWorld.class in the class file before, so there can be output!
Now delete irrelevant files and do it again!
Here **-d means encoding, and the following D:\code\class is the saved path, and we set a ClassPath variable in the environment variable, so that we can run java files in all files, otherwise we can To run in the directory where the .class** file is saved.
This is newly created, and the variable value is the save path of the **.class** file.