博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java Hello World程序
阅读量:2531 次
发布时间:2019-05-11

本文共 3084 字,大约阅读时间需要 10 分钟。

Whenever we start to learn a programming language, the first program is always to print the Hello World. In the last article, we learned . Now we are ready to write and run our first Hello World Java program.

每当我们开始学习编程语言时,第一个程序始终是打印Hello World。 在上一篇文章中,我们学习了 。 现在,我们准备编写并运行我们的第一个Hello World Java程序。

Java Hello World程序 (Java Hello World Program)

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.

将以上程序另存为JavaHelloWorldProgram.java

1.编译并运行Java Hello World程序 (1. Compile and Run Java Hello World Program)

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 JavaHelloWorldProgramHello World
or higher, then you can simply execute 或更高版本,则只需执行
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程序。

2. Java程序要点 (2. Java Program important points)

  1. A Java source file can have multiple classes but only one public class is allowed.

    一个Java源文件可以有多个类,但只允许一个公共类。
  2. The java source file name should be same as the public class name. That’s why the file name of our program is JavaHelloWorldProgram.java

    Java源文件名应与公共类名相同。 这就是我们程序的文件名为JavaHelloWorldProgram.java
  3. When we compile the code, it generates byte code and save it as 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的新文件
  4. When we execute the class file, we don’t need to provide complete file name. We need to use only the public class name.

    当我们执行类文件时,我们不需要提供完整的文件名。 我们只需要使用公共类名。
  5. When we run the program using java command, it loads the class into and looks for the in the class and runs it. The main function syntax should be same as specified in the program, else it won’t run and throw exception as Exception in thread "main" java.lang.NoSuchMethodError: main.

    当我们使用java命令运行程序时,它将类加载到并在类中查找并运行它。 主要函数语法应与程序中指定的语法相同,否则它将不会运行并引发异常,因为Exception in thread "main" java.lang.NoSuchMethodError: main

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程序创建了一个简短的视频。 观看它以获得更好的理解。

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 in java.

更新:阅读这篇文章,以了解 。

翻译自:

转载地址:http://gaozd.baihongyu.com/

你可能感兴趣的文章
raid5什么意思?怎样做raid5?raid5 几块硬盘?
查看>>
【转】how can i build fast
查看>>
null?对象?异常?到底应该如何返回错误信息
查看>>
django登录验证码操作
查看>>
(简单)华为Nova青春 WAS-AL00的USB调试模式在哪里开启的流程
查看>>
图论知识,博客
查看>>
[原创]一篇无关技术的小日记(仅作暂存)
查看>>
20145303刘俊谦 Exp7 网络欺诈技术防范
查看>>
原生和jQuery的ajax用法
查看>>
iOS开发播放文本
查看>>
20145202马超《java》实验5
查看>>
JQuery 事件
查看>>
main(argc,argv[])
查看>>
在线教育工具—白板系统的迭代1——bug监控排查
查看>>
121. Best Time to Buy and Sell Stock
查看>>
hdu 1005 根据递推公式构造矩阵 ( 矩阵快速幂)
查看>>
安装php扩展
查看>>
百度移动搜索主要有如下几类结果构成
查看>>
Python爬虫面试题170道:2019版【1】
查看>>
JavaBean规范
查看>>