Use txt to write Java code and execute it through cmd command

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

insert image description here


2. Write Java code

Write a simple code (the class name is our file name)

insert image description here


3. Save the file

After saving the file, change the file extension to .java

insert image description here


Fourth, open the cmd command window

Enter the cmd window from the current directory, click the small arrow ----> enter cmd----> press the Enter key
insert image description here


insert image description here


In this way, after opening cmd, we will find that the path we entered is the current path
insert image description here


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

insert image description here


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
insert image description here


6. Run the code through the cmd command

Execute the javac Compute command to run the code

java Compute

insert image description here


OK! ! ! Run successfully! ! !

Guess you like

Origin blog.csdn.net/qq_45344586/article/details/129758390