[Java course experience] How to use the dos window to execute java code

Compile HelloWorld.java program

In the dos command line, enter the directory java source files, use the javaccommand to compile
the command:

javac java source file name.java

For example:

javac HelloWorld.java

Insert picture description here
Insert picture description here
After the compilation is successful, there is no prompt on the command line. Open the directory of the source file and find that a new file HelloWorld.class is generated. This file is the compiled file, which is the executable file of java, called the bytecode file , there is With the bytecode file, you can run the program.

Run the HelloWorld program

In the dos command line, enter the root directory of the java source file and use the java command to run.

command

java 类名字

For example

java HelloWorld

java HelloWorld don't write don't write don't write class

Insert picture description here
The compiled code is:

public class HelloWorld {
    
    
    public static void main(String[] args) {
    
    
        System.out.println("HelloWorld");
    }
}

supplement

Just write the code in Notepad, and then change the file suffix to .java

Guess you like

Origin blog.csdn.net/maikotom/article/details/108806643