Java Hello World Program

A “Hello, World!” is a straightforward program that yields Hello, World! on the screen. Since it’s an exceptionally straightforward program, it’s regularly used to acquaint another programming language with a novice.

Let’s explore how Java “Hello, World!” program works.

In the event that you need to run this program in your PC, ensure that Java is appropriately introduced. Likewise, you need an IDE (or a content tool) to compose and alter Java code.

Like

// Your First Program
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!"); 
    }
}

On the off chance that you have replicated the careful code, you need spare the document name as HelloWorld.java. This is on the grounds that the name of the class and filename should coordinate in Java.

When you run the program, the output will be

Hello, World!

How Java “Hello, World!” Program Works?

// Your First Program

In Java, any line beginning with/is a remark. Remarks are planned for individual perusing the code to all the more likely comprehend the goal and usefulness of the program. It is totally disregarded the Java compiler (application that makes an interpretation of Java program to Java bytecode that PC can execute). To find out additional,

class HelloWorld { ... }

In Java, every application begins with a class definition. In the program, HelloWorld is the name of the class, and the class definition is:

class HelloWorld {
... .. ...
}

For now, just remember that, every Java application has a class definition, and the name of class should match the filename in Java.

public static void main(String[] args) { ... }

This is the main method. Every application in Java must contain a main method. The Java compiler starts executing the code from the main method.

How does it work? 

Good question. However, we will not discuss it in this article. After all, it’s a basic program to introduce Java programming language to a newbie. We will learn the meaning of publicstaticvoid, and how methods works? in later chapters.

For now, just remember that main function is the entry point of your Java application, and it’s mandatory in a Java program. The signature of main method in Java is:

public static void main(String[] args) {
... .. ...
}
System.out.println("Hello, World!");
  1. The following code prints the string inside quotation marks Hello, World! to standard output (your screen). Notice, this statement is inside the main function, which is inside the class definition.

Things to take away

  • Every valid Java Application must have a class definition (that matches the filename).
  • The main method must be inside the class definition.
  • The compiler executes the codes starting from the main function.

This is a valid Java program that does nothing.

public class HelloWorld {
    public static void main(String[] args) {
        // Write your code here
    }
}

You May Also Like

Abdul Vakeel

About the Author: Abdul Vakeel

WPBeginner Blog is a Free WordPress Resource Site For Beginners. WPBeginner Blog Was Founded in 4th June 2018 by Abdul Vakeel.The Main Goal of This Site is to Provide Quality Tips, Tricks, Hacks, and Other WordPress Resources That Allows WordPress Beginners to Improve Their Site.

Leave a Reply

Your email address will not be published. Required fields are marked *