In this lesson, you will learn.
Certainly! The “Hello, World!” program is a simple introductory program that is commonly used to demonstrate the basic syntax and structure of a programming language.
Here’s the Java First Hello World program
/**
* The HelloWorld class simply prints "Hello, World!" to
* standard output.
* @author is Dr. Amit Kumar
* This class demonstrates the use of documentation comments.
*/
public class HelloWorld {
public static void main(String[] args) {
// This is a single-line comment
System.out.println("Hello, World!");
/*
* This is a multi-line comment that can
* span over multiple lines.
*/
}
}
Output
Hello, World!
Let’s break down this program into its components for a detailed explanation.
Explanation
/** ... */
):@param
and @return
to describe method parameters and return values, respectively.Java Comments are of the following three types
public class HelloWorld
public
: This is an access modifier, meaning that the class is accessible by any other class.class
: it is a keyword used to define a class in Java.HelloWorld
: This is the name of the class. By convention, class names in Java should be nouns in UpperCamelCase.public static void main(String[] args)
public
: The main method is public, meaning that it can be called from outside of its class (in this case, by the Java runtime environment).static
: This means that the method can be run without creating an instance of the class containing it. It is necessary because the Java runtime environment calls the main method without creating an instance of the class.void
: This indicates that the method does not return any value.main
: This is the name of the method. This specific name is used by the Java runtime system to start the program.String[] args
: This is an array of String
objects named args
. It’s used to receive any command-line arguments that may be passed to the program.System.out.println
StatementSystem.out.println("Hello, World!");
: This is a call to the println
method of the out
object, which is a static member of the System
class.System
: This class provides facilities like standard input, output, and error output streams. It’s part of the java.lang
package, which is automatically imported into every Java program.out
: This static member of the System
class is an instance of PrintStream
, which is connected to the standard output of the system (typically a console).println
: This method prints the argument passed to it and then terminates the line (adds a new line at the end).
The following figure shows the execution process of a Java program i.e. “HelloWorld.java”
.java
) is compiled by the Java compiler (javac
) into bytecode (.class
file).main
method and starts the execution from it.
When you run this program, it will simply print “Hello, World!” to the standard output
There are no reviews yet. Be the first one to write one.
You must be logged in to submit a review.