How to Run Java Program?

To learn how to run Java program, first, ensure Java is installed, and the path is correctly set on your system. After installing the JDK, use the javac command to compile the Java file into platform-independent bytecode. This bytecode can be executed on any machine with a Java Virtual Machine (JVM) using the java command, producing the program's output.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Steps to Run a Java Program
Here, we will see how to run Java program using Notepad and Command Prompt. Let's see the process step-by-step:
Step 1: I have used the code given below to perform all the operations below. Open the Notepad, copy this code in the Notepad, and save that file with the extension .java.
You can see in the below images that I have written the Java code and saved it as test.java. Now, a new file will be created with the name test.java.



Step 2: You can see that inside the Art folder, there is a Java file named test.java.

Step 3: Now press Alt+D, and you will enter the above search bar.

Step 4: Type CMD and press enter key.

Step 5: You can see that the CMD is open. Now type javac test.java, as seen in the image below.

Step 6: You can see that a new file has been created with the .class extension. The file's name would be the name of the class you have used inside your program. In my case, I have used the Scaler as a class name.

Step 7: Now again, open the cmd and type the command java Scaler as you can see in the below image.

Step 8: At last, you will see that the content of the file has been displayed.

Note:
1: Java programs are compiled using the javac command. It takes .java files as input and generates bytecode.
2: The java command executes Java bytecodes. It processes bytecode as input, executes it, and produces the output.
Conclusion
- This guide highlights how to run Java program, starting from creating the Java file in Notepad to compiling and executing it.
- The javac command plays a crucial role in compiling Java programs, converting them into executable bytecode.
- To run a Java program, the java command is employed to execute the compiled bytecode, demonstrating the output of your program.
- Following these steps ensures a smooth process on how to run Java program, illustrating the seamless transition from code compilation with javac to execution with java.