Java Hello World

Hello World in Java

Java Hello World Program

Hello World is a simple Java program, for many the first they learn, that teaches syntax and components of the Java programming language.

The requirement for Java Hello World Code: For executing any java program, you need to

o          Install the JDK if you don’t have installed it, download the JDK and install it.
o          Set path of the jdk/bin directory.
o          Create the java program
o          Compile and run the java program

/*
* The HelloWorld Java program
*/
  classHelloWorld
  {
    public static void main(String[] args) 
     {
      System.out.println("Hello, World!"); 
     }
  }

Now compile that program using the command:

javac HelloWorld.java

Program Output:

Hello, World!

The “Hello World!” program consists of three primary components: the HelloWorld class definition, the main method and source code comments.

The following explanation will provide you with a basic understanding of the code:

  1. Class definition:This line uses the keyword class to declare that a new class is being defined.
class HelloWorld

HelloWorld is an identifier that is the name of the class. The entire class definition, including all of its members, will be between the opening curly brace  {  and the closing curly brace  } .

  1. main method: In Java programming language, every application must contain a main method whose signature is:

public static void main(String[] args)

public: So that JVM can execute the method from anywhere.

static: Main method is to be called without object.

The modifiers public and static can be written in either order.

void: The main method doesn't return anything.

main(): Name configured in the JVM.

String[]: The main method accepts a single argument:
                    an array of elements of type String.

Like in C/C++, main method is the entry point for your application and will subsequently invoke all the other methods required by your program.

  1. The next line of code is shown here. Notice that it occurs inside main( ).
System.out.println("Hello, World");

This line outputs the string “Hello, World” followed by a new line on the screen. Output is actually accomplished by the built-in println( ) method. System is a predefined class that provides access to the system, and out is the variable of type output stream that is connected to the console.

  1. Comments: They can either be multi-line or single line comments.
/* This is a simple Java program.
Call this file "HelloWorld.java". */

This is a multiline comment. This type of comment must begin with /* and end with */.

I hope this post helps you to understand Hello World and its implementation in Java programming language.

Keep coding 🙂

2 thoughts on “Java Hello World”

Leave a Reply

Your email address will not be published. Required fields are marked *