[Java] Getting Started: Write a simple Hello World code with Notepad and test it

After the JDK environment is configured ( necessary prerequisite ), we can try to write a simple Hello World code with the notebook that comes with the computer and run it;

Step 1: Create a Text Document

In any drive letter of this computer , select (or create) a folder to enter (here, take E:\a as an example) right-click the blank space  and select New --- Text Document

 Modify the file name (named " test " here as an example)

Open the document and copy the following code into it and save it :

class test
{
public static void main(String[] args) 
{
System.out.println("Hello World");
}
}

As shown in the picture. (tip: The file name with " * "   sign like this  means it is not saved , pay attention to check)

Step 2: Modify the file suffix

Change the .txt format to .java format, and select Yes if a pop-up window pops up .

 

 This is successfully modified to java format: 

 Note: If there is no response (the file has no .txt suffix or is still in the original text document format after modification), it may be that the extension name is not set to be visible ( solution: as follows ) or the jdk environment is not configured properly ( solution : re-check , you can refer to [Java] development environment configuration: JDK configuration and Eclipse installation (1)_This blog I don’t know-CSDN blog )

The solution to the invisible extension : open this computer -- view -- check the file extension

Step Three: Test

Press win+R on the keyboard at the same time . Enter cmd to open the command operator;

Goal 1: Switch to the path where the document is located;

Because my document is not in the default C drive, so I enter e here  : (meaning to switch the drive letter to E drive)  

If it is saved in the C drive (c:), there is no need to modify it,

If you are in D, F, etc., enter d:     f:

The same goes for other disks ;)

My java file is under E:\a , so here I enter cd a

(meaning, switch to the next level, the folder named a)

(If you want to go back one level, type cd .. )

For details, refer to DOS command operation:

1. Shortcut key: windows+R   to call out the DOS window.

2. Enter cmd (case insensitive) and press Enter to open the DOS window.

Common commands (basically not case-sensitive)

1. Switch the drive letter: Drive letter (that is, the C, D, E.. drive of the computer): (eg:    D :   )

2. View files or folders:   dir

3. Enter a folder:     cd  folder name

4. Return to the previous directory:     cd..

5. Clear screen:   cls

6. Delete a file:    del    file name

7. Delete a folder:  rd   folder name

8. Exit the DOS window:  exit

 Goal 2: Use javac and java commands;

What we wrote earlier is a simple java source code , we need to use the javac command to program it into a bytecode file before it can run;

Go back to the E:\a path where the document is located, and enter javac test.java (for class writing)

 We can see that there is an additional column of class type files in the directory.

Use the java command to execute the class bytecode file, enter java test and press Enter:

At this point, the code is executed and Hello World is printed out, indicating that the operation is successful.

---This is the end of this article---

Guess you like

Origin blog.csdn.net/m0_73964392/article/details/129440266