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

青灯夜游
Release: 2019-11-28 15:52:08
forward
4885 people have browsed it

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 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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!