Example Program:

class HelloWord
 {
     public static void main(String args[])
     {
          System.out.println(“Welcome to Java”);
      }
 }

Explanation:

class HelloWord:

  • Class is a keyword and HelloWord is the name of the class.

public:

  • The public keyword is an access specifier, which means that the content of the class can be accessible from everywhere.

static:

  • The keyword static allows main() to be called without creating an instance of a class because it is the first method that will be called when program executes

void:

  • The keyword void tells the compiler that main () does not return any value.

main():

  • main is a method called first when a java application begins
  • Java is case-sensitive. Main is different from main

 String args[]:

  • It declares a parameter named args, which is an array of class string.
  • args[] receives any command-line argument supplied with main() at the time of execution.

 System.out.println():

  • System is predefined class that provides access to the system.
  • Out is the output stream that is connected to the console.
  • Output is displayed by the built-in println() or print() Println() displays the string which is passed to it.
  • It is similar to a printf() function of the C language

Compilation

Javac HelloWord.java

  • This command will compile the source file and if the compilation is successful it will generate a class file with the same name as of the class (HolloWord.class). It contains bytecode

 Java HelloWord

  • This command called ‘java’ takes the bytecode and runs the bytecode on JVM environment in interpreted mode.
  • Output: Welcome to Java