官术网_书友最值得收藏!

Executing our program

So what do we do with this? Well, as we know, our computer can't read this Java code directly. It must convert it into a computer-readable language. So executing this code becomes a two-step process:

  1. Compiling our program: First, we're going to ask NetBeans to build our project. This means that all of the code within our project will be compiled and converted into computer-readable code in a, essentially, computer-readable project:

When we press the Build Project button, we'll see a bunch of text in our output box at the bottom of the screen--hopefully the nice BUILD SUCCESSFUL message, followed by the time it took to build the project:

  1. Running our program: Once we've built our project, we can press the Run Project button to execute our code and our println statement:

NetBeans will then give us the following pop-up box:

When we execute a program outside of an IDE, we execute it by launching one of its executable files. Because we're in an integrated development environment right now, NetBeans wants to be sure which of our files we would like to be the entry point of our program. We only have one option here because we've only written one Java class. So let's confirm to NetBeans that HelloWorld is our main class and the main() function in the HelloWorld program will, therefore, be where we start executing our Java program. Then, when we hit OKour output box will tell us the program has begun to run and our program then prints "Hello World!" to the output box as we intended:

There we have it! Now we're Java programmers. Of course, there's more than a little bit left to learn. In fact, HelloWorld in Java is probably the simplest program you'll ever write. Java is extremely powerful, and the reality is we simply can't hope to appreciate all of its intricacies while writing our first program. The really good news is that from this point on, we need to take far fewer leaps of faith and we can begin to build a very solid understanding of Java by taking a step-by-step approach.

主站蜘蛛池模板: 宁津县| 闽清县| 咸丰县| 灵丘县| 观塘区| 那曲县| 涟源市| 鹤岗市| 新龙县| 甘孜县| 昔阳县| 芜湖县| 麟游县| 肥城市| 铁岭市| 年辖:市辖区| 景洪市| 杨浦区| 临西县| 潢川县| 新源县| 白城市| 皋兰县| 新河县| 涿州市| 鄂尔多斯市| 邻水| 格尔木市| 安溪县| 玉溪市| 会泽县| 湖北省| 砀山县| 南开区| 庆城县| 江门市| 汝阳县| 新兴县| 偃师市| 大同市| 民乐县|