“Hello World..!” program in Java

Hello World..!” – Probably the first message that any developer tries to print on the console, while learning a new programming language.

Let’s write a basic Java program to print “Hello World..!” message on the console and go through each keyword in the program.

Output:

 

Let’s go through each statement in the program.

This statement specifies the compiler that we are going to create a class called “HelloWorld” in the package “org.sample”.

 

This is how a class is created in Java. “public” is a keyword and access modifier in Java that specifies this class can be visible for all classes in the other packages. “class” is another keyword that is used for creating a Class. “HelloWorld” is the class name.

 

This is how a method is defined in Java.

  • “public” is a keyword and access modifier in Java that specifies this method can be visible to all classes in the other packages.
  • “static” is another keyword that specifies this method can be called without creating instance of the class.
  • “void” is another keyword that specifies this method returns nothing.
  • “main” is the name of the method. In Java, main() is the starting point of execution when a program is executed.
  • “String[] args” is the parameter declaration of the method. This parameter is used for passing command line arguments to the program.

 

This line displays the message “Hello World.!!” to the standard output.

  • “System” is the predefined class that provides access to the system.
  • “out” is the output stream that is connected to the console.
  • “println()” is the built-in method which outputs the message to the console.

 

“print()” and “println()” both are built-in methods which are used for printing the message to the output stream. the only difference is

  • “print()” outputs the message in the same line where as “println()” outputs the message in the new line.

 

 

Leave a Reply

Your email address will not be published.