Article Directory
foreword
To execute Java files with the cmd command, first we need to configure the JDK environment on the machine
在此附上JDK1.8安装文档
Super detailed JDK1.8 installation and configuration
1. Create a .txt file
Note: To write Java code with .txt files, our file name is our class name (class name naming convention: the first letter of the class name is capitalized), for example, the author named this file Compute
2. Write Java code
Write a simple code (the class name is our file name)
3. Save the file
After saving the file, change the file extension to .java
Fourth, open the cmd command window
Enter the cmd window from the current directory, click the small arrow ----> enter cmd----> press the Enter key
In this way, after opening cmd, we will find that the path we entered is the current path
5. Compile and generate .class files through the cmd command
Execute javac Compute.java command to compile and generate Compute.class file
javac Compute.java
After running the javac Compute.java command, we found that the Compute.class file was generated in the file explorer. The generation of the .class file means that we can run the code
6. Run the code through the cmd command
Execute the javac Compute command to run the code
java Compute
OK! ! ! Run successfully! ! !