-
Install Java Development Kit (JDK) on your computer. You can download the latest version of JDK from the official Oracle website.
-
Open a text editor such as Notepad, Sublime Text, or Visual Studio Code.
-
In the text editor, type the following code:
public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello, World!”); } }
-
Save the file with the name “HelloWorld.java”. Note that the file name should match the name of the public class in the code.
-
Open the command prompt (Windows) or terminal (Mac or Linux).
-
Navigate to the directory where you saved the “HelloWorld.java” file using the
cd
command. -
Compile the Java program by typing the following command:
javac HelloWorld.java
This will generate a file called “HelloWorld.class” in the same directory.
- Run the Java program by typing the following command:java HelloWorld
This will execute the program and output the following text:
Hello, World!