📅  最后修改于: 2023-12-03 14:42:14.455000             🧑  作者: Mango
Java Hello World is a classic introductory program for programmers learning the Java programming language. It is often the first program that developers write when starting to learn Java.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Let's analyze the code:
public class HelloWorld
: In Java, the code is organized into classes. A class is a blueprint for creating objects. Here, we have a class named HelloWorld
.public static void main(String[] args)
: Every Java program must have a main
method, which is the entry point of the program. It is invoked when the program is executed. The void
keyword means that the main
method does not return any value.System.out.println("Hello, World!");
: This line of code prints the string "Hello, World!" to the console. The System.out
is a reference to the standard output stream, and println
is a method that prints the given string followed by a newline.To run this program:
.java
extension, for example, HelloWorld.java
.javac HelloWorld.java
. This will create a bytecode file named HelloWorld.class
.java HelloWorld
. You should see the output Hello, World!
printed on the console.Congratulations! You have successfully written and executed the Java Hello World program. This is just the beginning of your journey as a Java programmer.