Home  >  Article  >  Java  >  Detailed explanation of how to compile and run Java files using the cmd command line

Detailed explanation of how to compile and run Java files using the cmd command line

青灯夜游
青灯夜游forward
2019-11-28 15:52:084969browse

Using the cmd command line under Windows, you can call javac.exe and java.exe in the jdk to compile and execute the java file, provided that the jdk has been successfully installed and the relevant environment variables are correctly configured. Next, let's learn how to compile and run a Java program using the cmd command line.

Detailed explanation of how to compile and run Java files using the cmd command line

1. Using the cmd command line under windows, you can call javac.exe and java.exe in jdk to compile and execute java files. The premise is that jdk Successfully installed and correctly configured relevant environment variables. [Recommended learning: java video tutorial]

2. After the JAVA running environment is successfully configured, find the Java source code you wrote (the file with the suffix .Java). As shown below, my Java file (random.java (randomly output 5 English letters)) is in the JAVA folder of the D drive.

Detailed explanation of how to compile and run Java files using the cmd command line

#3. Open cmd and enter the folder where the .Java file is located. Since my source files are in the JAVA folder of the D drive, I need to enter the D drive first (enter d: Enter)

Detailed explanation of how to compile and run Java files using the cmd command line

4. After entering the D drive, Enter the JAVA folder. After entering cd JAVA, press the Enter key.

Detailed explanation of how to compile and run Java files using the cmd command line

5. Enter javac random.java and press the Enter key to compile the program.

Detailed explanation of how to compile and run Java files using the cmd command line

#6. If no error is reported, a .class file will be generated in the directory where the .java file is stored.

Detailed explanation of how to compile and run Java files using the cmd command line

7. After the compilation is successful, enter java random and run the program. The running result is 5 English letters randomly output, indicating that the program is running successfully.

Detailed explanation of how to compile and run Java files using the cmd command line

This article comes from the java Getting Started column, welcome to learn!

The above is the detailed content of Detailed explanation of how to compile and run Java files using the cmd command line. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete