Write a simple Hello program with the command line
surroundings
First, prepare the environment for writing Java programs, download jdk,
please see: jdk download and configuration
step
To write a Java program, the steps are: 1. Write the source code, 2. Compile the source code, 3. Run.
Write source code
Create a new text file, change the file name to Hello.java, and write the code in the text. Note that the code is an English symbol. The parentheses are in pairs. Remember the directory where the file is located. When compiling, you need to jump to the directory where the file is located.
The code is as follows:
public class Hello{ public static void main(String[] args){ System.out.println("hello!world!"); } }
Edit source code
1. Enter the DOS environment, quickly build win+r, enter cmd and press Enter.
2. In the command line mode, enter the directory where the program is located, and execute the javac Hello.java command to compile the program.
DOS command jump:
cd+space+a file name in the directory: enter a file in the directory
cd...: go back to the previous directory.
cd\: Go back directly to the root directory.
dir: View the file under the current address.
As shown below:
After success, there will be an extra Hello.class file.
As shown below:
Run the program
After the compilation is successful, you can run the program and continue typing java Hello to execute the program and output a line of "Hello!word!"
In this way, the first small program is written.