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.
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.
#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)
4. After entering the D drive, Enter the JAVA folder. After entering cd JAVA, press the Enter key.
5. Enter javac random.java and press the Enter key to compile the program.
#6. If no error is reported, a .class file will be generated in the directory where the .java file is stored.
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.
This article comes from thejava Getting Startedcolumn, 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!