【Day-2】Java自學(xué)筆記 - HelloWorld
1.Java程序的過程能夠被簡化為三步:
? 在文本編輯器輸入和把它保存成文件 -?HelloWorld.java
? 在terminal窗口編譯這個文件 - javac HelloWorld.java
??在terminal窗口運(yùn)行這個文件 - java HelloWorld.java
2.Hello World
Ouput:?
3.分析一下上面的代碼
時間復(fù)雜度:O( 1 ).? ?// 待分析
空間復(fù)雜度:O( 1 ).? ?// 待分析
<1>. class定義 -?使用Class關(guān)鍵字來聲明了一個新類
<2>. HelloWorld - 類名
<3>. main方法
在Java編程語言中,每一個應(yīng)用都應(yīng)該包含一個main方法。main方法時Java程序的主入口。而且它是強(qiáng)制性的。
? public :JVM無論在哪都可以執(zhí)行main方法
? static :? 主要方法是在沒有對象的情況下調(diào)用。修飾符public和static可以按任意順序編寫?. [ ? ]
? void : main方法沒有返回任何東西
??main() :?JVM中配置的名稱。main方法必須在類定義內(nèi)。編譯器總是從主函數(shù)開始執(zhí)行代碼。[?Name configured in the?JVM. The main method must be inside the class definition. The compiler executes the codes starting always from the main function. ]?
??String[] :?main方法接受單個參數(shù),即String類型的元素?cái)?shù)組。
4. 注意點(diǎn)
?? 程序定義的類名為HelloWorld,與文件名(HelloWorld.java)相同。這不是巧合。在Java中,所有代碼都必須駐留在一個類中,并且最多有一個公共類包含main()方法。【?The name of the class defined by the program is HelloWorld, which is the same as the name of the file(HelloWorld.java). This is not a coincidence. In Java, all codes must reside inside a class, and there is at most one public class which contains the main() method.】
???按照慣例,主類(包含主方法的類)的名稱應(yīng)該與保存程序的文件的名稱匹配。【?By convention, the name of the main class(a class that contains the main method) should match the name of the file that holds the program.】
???每個Java程序都必須有一個與文件名匹配的類定義(類名和文件名應(yīng)該相同)。【 Every Java program must have a class definition that matches the filename (class name and file name should be same). 】
5. sout
System.out.println("Hello, World"); - 可以通過在idea里打sout快速生成。這個會在控制臺輸出Hello,World