Java Hello World

Soumyadip
The Dev Newbie
Oct 23, 2020

--

Hello World

A “Hello, World!” is a simple program that outputs Hello, World! on the screen.

The code for it in the latest version of Java is as follows:

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

How “Hello, World” Works in Java

// Your First Program

In Java, any line starting with// is a comment. Comments are intended for users reading the code to better understand the intent and functionality of the program. It is completely ignored 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, 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 the class should match the filename in Java.

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

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

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

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

Finally, the above code prints the string inside quotation marks Hello, World! to the standard output (your screen). Notice, this statement is inside the main function, which is inside the class definition.

--

--

Soumyadip
The Dev Newbie

HTML, CSS, Angular and Java amateur at 16 years old. Is also learning UI/UX design as an encore.