课程: Learning Java 17
Run your first Java program
- [Instructor] We have a few options for running a Java program in IntelliJ. One option is to left-click the class name and select Run HelloWorld.main. HelloWorld is the class and main is the function. By selecting Run HelloWorld.main, the IDE compiles the program and it runs it for us. There are no manual commands to type in. We just click the button and it runs. After running the program, you'll notice a small window at the bottom of the screen. This contains our output. Hello World! It's me, Kathryn. This window is called the console. It's a text display where the executor of the program can see output messages. Now when we ran this program, we had to do two button clicks. We left-clicked the HelloWorld class and then we selected Run HelloWorld.main. What if we could run the program with just one button click? When we initially ran the program, we actually created a run configuration. We can look at this configuration in the top right-hand corner. Let's edit it. The name of this configuration is HelloWorld. It's using Java 17 and the entry point for this program lives in the HelloWorld class. The entry point is that main function. We don't want to change anything, so let's click Cancel. The Play button in the right-hand corner is now green. It's not grayed out. Let's click it. In the console, we get what we expect, that same HelloWorld message. You just developed and executed your first Java program using an IDE.
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。