Write a Java Hello world program that prints the message java “Hello, World!” to the console. Make sure your program follows proper syntax and structure, including the use of a class and a main method.

java Hello World program

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

				
			
java hello world

In this program:

  • public class HelloWorld': This line declares a class named ‘HelloWorld‘.
  • public static void main(String[] args)‘: This line declares the main method, which is the entry point of the program. It takes an array of strings (‘args') as input. It’s marked as ‘public‘, ‘static‘, and ‘void‘ because it does not return any value.
  • System.out.println("Hello, World!");': This line prints “Hello, World!” to the console. ‘System.out' is a predefined PrintStream object representing the standard output stream. ‘println()‘ is a method of the PrintStream class that prints a line to the output stream.
 
Scroll to Top