in , ,

Java Hello World Program

Java Hello World Program

Java Hello World Program

In this tutorial, you will learn to write “HelloWorld” program in Java.

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

How about we investigate how Java “Hello, World!” program works.

If you need to run this program on your computer, ensure that Java is appropriately installed. Likewise, you need an IDE (or a text editor) to write and alter Java code. For that, check How to run Java on your computer?


Java “Hello, World!” Program

// Your First Program

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

If you have replicated the specific code, you have to spare the file name as HelloWorld.java. This is on the grounds that the name of the class and filename should coordinate in Java. Visit this page to learn: Why are filenames in Java the same as the class name?

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 comment. Comments are expected for users perusing the code to all the more likely comprehend the expectation and usefulness of the program. It is totally overlooked by the Java compiler (an application that translates Java program to Java bytecode that computer can execute). To learn more, visit Java comments.

class HelloWorld { ... }

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

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

For the time being, simply recollect that each Java application has a class definition, and the name of the class should coordinate the filename in Java.

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

This is the main technique. Each application in Java must contain the primary technique. The Java compiler begins executing the code from the fundamental strategy.

How can it work? Good question. However, we won’t examine it in this article. All things considered, it’s an essential program to acquaint the Java programming language toa newbie. We will learn the meaning of public, static, void, and how methods work? in later chapters.

Until further notice, simply recall that the fundamental function is the section purpose of your Java application, and it’s obligatory in a Java program. The mark of the primary strategy in Java is:

public static void main(String[] args) {
... .. ...
}
System.out.println("Hello, World!");

The accompanying code prints the string inside quotes Hello, World! to standard yield (your screen). Notice, this announcement is inside the primary capacity, which is inside the class definition.


Things to remove

Each legitimate Java Application must have a class definition (that coordinates the filename).

The fundamental technique must be inside the class definition.

The compiler executes the codes beginning from the fundamental function.

This is a valid Java program that does nothing.

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

Try not to stress if you don’t understand the meaning of class, static, methods, and so on for now. We will discuss it in detail in later chapters.


Thanks for watching! We hope you found this tutorial helpful and we would love to hear your feedback in the Comments section below. And show us what you’ve learned by sharing your photos and creative projects with us.

salman khan

Written by worldofitech

Leave a Reply

How to Make a Wedding Program in CorelDRAW

How to Make a Wedding Program in CorelDRAW

How to Make a Restaurant Menu in CorelDRAW

How to Make a Restaurant Menu in CorelDRAW