Hello world program in Java

Nowadays, Java is the most widely used programming language for computer-based applications. In this article, we discuss the basic program of java. When we learn about a new programming language, it becomes necessary to start with a basic program. To learn the basics and syntax of programming language traditionally, we start with an easy program which is called “Hello World”.

As we know, Java is a platform independent language; therefore, we adopt the easier way to write out the first java program. In this way, you do not need an editor to download on your computer or any online editor.


There are some prerequisite applications must be installed in your computer before the execution of a java program.

  • Download and install the JDK kit.
  • Set the path of jdk/bin directory.

How to run your first Java Program

In the following section, we learned how to write a simple “Hello World” program in Java programming language and run it on your system for the first time. All steps are given below with proper examples.

Step 1

First, open the notepad or any text editor. In windows, open the start bar on your computer’s window and search the notepad as shown in the given image:

Step 2

In notepad, write the source code of your Java program:

class ClassName{
  public static void main(string args[]){
    System.out.println("Hello Linuxhint");  

Following parameters are the part of above java code

Class: It is used to define a class in java.

Public: It shows that the declared variable is accessible everywhere in program.

Static: When a static method is declared it means to invoke the static function no object is needed.

void main: shows that a program is started from here.

String args[]:shows the command line argument.

System.out.printIn(): this command is used to print results.

Step 3

After writing your first java code, save the file with the “.java” extension e.g. “”.

Step 4

To compile the code, open up the command prompt and go to the relative directory where java code file is saved using cd command i.e. “cd C:/workspace”:

> cd C:/workspace

And execute the command given below to compile your program:

> javac

Step 5

Once the code is compiled, go to your “workspace” folder and you will find a class file named as “ClassNAme.class”. This class file is generated after the compilation of your program.

Note: Java is a compiler and interpreter based language. Therefore, after the compilation of the program, a class file is generated because the javac compiler converts the code into byte code. As shown in the given image.

Step 6

Lastly, execute the command given below to run the java program:

After the execution of the command, the “Hello World” will be successfully printed.

This is how you can write, compile, and run your first java program in windows operating system.


To run your java, first you need to download and install the JDK kit and set the path of jdk/bin directory. Afterwards, to create and run your first “Hello World” program in Java, initialize of class, declare of the main() method and use System.out.println(“Hello World”) statement to print “Hello World”. This article contains the basic steps of how to write the first program in java.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.