Writing your very first program! This classic "Hello, World!" example is perfect for getting started because it introduces basic Java syntax without being overly complicated. Don't worry if every line doesn't make perfect sense right now; we'll break down the details in future tutorials. For now, just follow these steps to write and run your program. The Code Here's the simple Java program you'll be working with: Java public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } } Step-by-Step Instructions Open a Text Editor: Start by opening a plain text editor on your computer. Notepad (Windows), TextEdit (macOS), or any code editor like VS Code or Sublime Text will work perfectly. Write the Code: Carefully type or copy the Java code provided above into your open text editor. Pay close attention to capitalization, punctuation, and curly braces {}. Save the File: This is a crucial step! Save the file with the name Main.java. It's important that the file name exactly matches the class name declared in the code (public class Main). Choose a simple, easy-to-access location, like a new folder on your desktop (e.g., C:\JavaPrograms on Windows or ~/Desktop/JavaPrograms on macOS/Linux). Open Your Command Prompt/Terminal: You'll need to use your computer's command line to compile and run the program. Windows: Search for "Command Prompt" in your Start menu. macOS/Linux: Search for "Terminal." Navigate to Your Program's Location: In the command prompt/terminal, use the cd (change directory) command to go to the folder where you saved Main.java. For example, if you saved it in C:\JavaPrograms, type: Bash cd C:\JavaPrograms If you saved it in ~/Desktop/JavaPrograms on macOS/Linux, type: Bash cd ~/Desktop/JavaPrograms Compile the Program: Now, use the Java compiler (javac) to convert your human-readable Java code into bytecode that the computer can understand. Type: Bash javac Main.java Press Enter. If there are no errors, you won't see much output, but a new file named Main.class will be created in the same folder. This is your compiled program! Run the Program: Finally, use the Java Virtual Machine (java) to execute your compiled program. Type: Bash java Main Important: Notice you don't include the .java or .class extension here. Just the class name Main. See the Output! After pressing Enter, you should see: Hello, World! Congratulations! You've just written and run your first Java program! This "Hello, World!" program is your first step into the world of Java. As the note says, it helps you understand the basic structure. Are you ready to move on and explore what each part of this program actually does?

视频信息