Whenever we start to learn a programming language, the first program is always to print the Hello World. In the last article, we learned how to install Java on Windows 10. Now we are ready to write and run our first Hello World Java program.
每當我們開始學習編程語言時,第一個程序始終是打印Hello World。 在上一篇文章中,我們學習了如何在Windows 10上安裝Java 。 現在,我們準備編寫并運行我們的第一個Hello World Java程序。
簡單的java程序。To keep things simple and working for a new user, here is the sample hello world program that you can use.
為了使事情變得簡單并為新用戶工作,這里是您可以使用的示例hello world程序。
public class JavaHelloWorldProgram {public static void main(String args[]){System.out.println("Hello World");}
}
Save above program as JavaHelloWorldProgram.java
in any directory.
java小應用程序? 將以上程序另存為JavaHelloWorldProgram.java
。
Open Command Prompt and go to the directory where the hello world program file is saved. Then execute the below commands in order.
打開命令提示符,然后轉到保存hello world程序文件的目錄。 然后依次執行以下命令。
$javac JavaHelloWorldProgram.java$java JavaHelloWorldProgram
Hello World
java JavaHelloWorldProgram.java
and it will compile and execute the program for you. No need to explicitly compile and then run the java program.java JavaHelloWorldProgram.java
,它將為您編譯并執行程序。 無需顯式編譯然后運行Java程序。 JavaHelloWorldProgram.java
Java源文件名應與公共類名相同。 這就是我們程序的文件名為JavaHelloWorldProgram.java
Class_Name.class
extension. If you look at the directory where we compiled the java file, you will notice a new file created JavaHelloWorldProgram.class
當我們編譯代碼時,它將生成字節代碼并將其另存為Class_Name.class
擴展名。 如果查看我們編譯Java文件的目錄,您會注意到創建了JavaHelloWorldProgram.class
的新文件 Exception in thread "main" java.lang.NoSuchMethodError: main
. 當我們使用java命令運行程序時,它將類加載到JVM中并在類中查找main方法并運行它。 主要函數語法應與程序中指定的語法相同,否則它將不會運行并引發異常,因為Exception in thread "main" java.lang.NoSuchMethodError: main
。 Java開發?I have recently created a short video for Java Hello World Program using Notepad and then Eclipse. Watch it for a better understanding.
我最近使用記事本和Eclipse為Java Hello World程序創建了一個簡短的視頻。 觀看它以獲得更好的理解。
演示地址
hello world動畫,That’s all for this post and you can start playing with your first class. In the next post, I will get into further details of classes, JDK, JVM, and other features provided by the Java programming language.
這就是這篇文章的全部內容,您可以開始上一堂課。 在下一篇文章中,我將進一步探討類,JDK,JVM和Java編程語言提供的其他功能的詳細信息。
Update: Read this post to know about JDK vs JRE vs JVM in java.
Java程序設計、 更新:閱讀這篇文章,以了解Java中的JDK,JRE和JVM 。
翻譯自: https://www.journaldev.com/481/java-hello-world-program
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态