Home Java Hello, World! – Your First Java Program

Hello, World! – Your First Java Program

hello world

In our previous post we learned “What is Java“.

In this tutorial, you will learn how to write “Hello World” in Java.

To run this program on your computer you need to install Java on your machine. To install visit java.com.

Here are the followings steps:

Step 1:

Open your preferred IDE or text editor like notepad or notepad++ and write the below code

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!"); 

Save the file name as HelloWorld.java, it’s because the name of the class and filename should match in Java.

Step 2:

Open terminal or command prompt and navigate to the directory where you have saved your java file.

To compile the code use javac command with the file name, this will compile your java code and will create a corresponding class file.

Step 3:

To execute the program use command java with class name.

When you run the program, the output will be:

Congratulations, you have successfully executed your first java program.

This site uses Akismet to reduce spam. Learn how your comment data is processed.