Curriculum
Course: Learn Java Programming
Login

Curriculum

Learn Java Programming

Text lesson

Creating Hello World Java Program

In this lesson, you will learn.

  • First Java ‘Hello World’ Program
  • Execution Process of Java Program

 

First Java ‘Hello World’ Program

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

 

Example: ‘Hello World’ Java 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

1. Documentation Comments (/** ... */):

  • These are used to create documentation for the Java code.
  • They often contain tags like @param and @return to describe method parameters and return values, respectively.

Java Comments are of the following three types

2. Class Declaration: 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.

2. Main Method: 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.

3. The System.out.println Statement

  • System.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).

 

Execution Process of Java Program

The following figure shows the execution process of a Java program i.e. “HelloWorld.java”

  1. Compilation: First, the Java source file (.java) is compiled by the Java compiler (javac) into bytecode (.class file).
  2. Execution: Then, the Java Virtual Machine (JVM) executes this bytecode. The JVM looks for the main method and starts the execution from it.

 

When you run this program, it will simply print “Hello, World!” to the standard output

 

 


End of the lesson….enjoy learning

 

Student Ratings and Reviews

 

 

There are no reviews yet. Be the first one to write one.

 

 

Submit a Review

 

 

Layer 1
Login Categories