Hello World Java Program

This is how we would write a Hello World program in java

package com.hello.pkg;

public class HelloWorld {

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


Here is the explanation

public class HelloWorld

(1) public - It is an access modifier

(2) class - This is a Java class


 public static void main(String args[]) 

(1) public - public access modifier on the method

(2) static - the method can be accessed without creating an object of HellloWorld class

(3) void - there is no return type for main method

(4) main - name of the method, the main method is the entry point for any java application

(5) String[] args means an array of sequence of characters (Strings) that are passed to the "main" function. This happens when a program is executed.

Example when you execute a Java program via the command line:

java HelloWorld test one

Therefore, the array will store: ["test", "one"]


No comments:

 Python Basics How to check the version of Python interpreter mac terminal

Popular in last 30 days