Site icon DED9

Learn Hello World In Java (In Very Simple Language)

Hello World! Is a simple program that outputs Hello, World! Prints on the screen. Because the program is so simple, it is usually used to introduce a new programming language to a new user.

Let’s check out the “Hello World!” how it works.

If you want to run this program on your system, make sure Java is installed correctly. You also need an IDE (or text editor) to write and edit Java code.

Hello World application in Java

  1. // Your First Program
  2. class HelloWorld {
  3. public static void main (String [] args) {
  4. System.out.println (“Hello, World!”);
  5. }
  6. }

If you copied the code accurately, you must save the file name HelloWorld.java. Because the class name and file name in Java must match.

When you run the program, the output is:

Hello, World!

“Hello World!” How does it work in Java?

 // Your First Program

In Java, any line starting with // is a comment. Comments to read the description of the code and understand more about it. The Java compiler completely ignores these lines (the application that executes Java code for the computer).

 class HelloWorld……

In Java, every program starts with a class definition. In the above program, HelloWorld is the class name and the class definition is:

class HelloWorld {

… ..…

}

Remember that every Java program has a class definition, and the class name must match the file name in Java.

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

The top line is the main method. Every program in Java must have a main method. The Java compiler starts executing the code from the main method.

Remember that the main function is the Java entry point of the mandatory program. The signature of the main function in Java is equal to:

public static void main (String [] args) {

… ..…

}

 System.out.println (“Hello, World!”);

The above code prints the string inside the quotation mark in the standard output (screen). Note, this is the line of code inside the main function that is inside the class definition.

important points

  • Every valid Java program must have a class definition (which matches the file name).
  • The main function must be in the class definition.
  • The compiler starts executing the code from the main function.

The following code is a valid Java program that does nothing.

public class HelloWorld {

public static void main (String [] args) {

// Write your code here

}

}

If you do not understand the meaning of class, static, methods and., Do not worry. We will explain them in full in the following sections.

Exit mobile version