Command window implements Java code

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
insert image description here
2:
insert image description here

This enters the cmd command window!

insert image description here
**javac: ** Generate class files:

insert image description here
insert image description here

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.

insert image description 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!

insert image description here

Now delete irrelevant files and do it again!

insert image description here

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.
[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 (img-RLcQo4tU-1631456119370) (C:\Users\...\AppData\Roaming\Typora\typora-user- images\image-20210909000539640.png)]

[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 (img-dzFfon4t-1631456119370) (C:\Users\...\AppData\Roaming\Typora\typora-user- images\image-20210909000616319.png)]

[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 (img-a1JXD9kX-1631456119371) (C:\Users\...\AppData\Roaming\Typora\typora-user- images\image-20210909000509737.png)]

This is newly created, and the variable value is the save path of the **.class** file.

Guess you like

Origin blog.csdn.net/weixin_51961968/article/details/120257129