A Hello World Program

class MyClass {
      public static void main(String args[]){
              System.out.println("Hello World!");
  • In Java ,every line of code that can actually run needs to be inside a class.(e.g MyClass) and every program must have class and starts from main method.

Main Method:-To run our program , the main method must be identical to this Signature:

# public static void main(String args[])   OR
# public static void main(String[] args)
  • Public : anyone can access it.
  • static : method can be run without creating an instance of the class containing the main method.
  • void : method does not return any value.
  • main : the name of the method.
  • The main method has parameters (String args[] ) i.e it is array of Strings called args.

System.out.println() : The body of main method , enclosed in curly braces:

           System.out.println("Hello World");
  • The println method prints a line of text to the screen but theĀ  System class and its out stream are used to access the println method.