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.
![](https://amitkhurana.dev/wp-content/uploads/2020/04/1-1.png)
![](https://amitkhurana.dev/wp-content/uploads/2020/04/1-2.png)
Step 3:
To execute the program use command java with class name.
When you run the program, the output will be:
![](https://amitkhurana.dev/wp-content/uploads/2020/04/2-1.jpg)
Congratulations, you have successfully executed your first java program.