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

The main() function

Java code, like the English language, is read top down and left to right. Even if our project contains many files and many classes, we still need to start reading and executing our code at a specific point. We named this file and class HelloWorld, the same name as our project, because we would like it to be special and contain the public static void main(String[] args) method where the execution of our code will begin. That's quite a mouthful of jargon. For now, just type it out and know that this is the area of our code from where our Java program will begin reading and executing. Once again, this will become much clearer as we begin to learn Java; just know this is the starting point of our Java program. The main() function's code is enclosed in curly brackets:

public class HelloWorld {
public static void main(String[] args) {
}
}

One of the great things about working in an IDE is that it will highlight which brackets correspond to each other. The brackets allow us to place code within other areas of code. For example, our main() method is contained within the HelloWorld class, and the Java code which we're about to write and execute is going to be contained in our main() method. Line 4, which currently contains nothing, is where our program will look to start reading and executing the Java code.

主站蜘蛛池模板: 绥宁县| 林芝县| 太仆寺旗| 丽水市| 广南县| 洞口县| 龙泉市| 若尔盖县| 团风县| 军事| 子洲县| 临高县| 香港| 肇东市| 台中市| 来安县| 彭州市| 玉树县| 隆化县| 长泰县| 广安市| 班戈县| 桃源县| 仁布县| 北辰区| 深泽县| 德惠市| 东辽县| 安徽省| 宁化县| 南康市| 鹰潭市| 苏尼特左旗| 杭锦后旗| 安庆市| 波密县| 如东县| 玉溪市| 吉水县| 新平| 白朗县|