Table of contents
1.
Introduction
2.
Why Learn to Run Java Programs Manually?
2.1.
1. Understanding the Compilation and Execution Process
2.2.
2. Troubleshooting and Debugging
2.3.
3. No Dependency on IDEs
2.4.
4. Useful for Interviews and Exams
3.
Steps to Run a Java Program
3.1.
Installing Java Development Kit (JDK)
3.2.
How to Create a Java File in Notepad
3.3.
Naming Convention
3.4.
How to Compile Java Program Using javac
4.
Types of Java Programs
5.
Security Considerations
6.
Frequently Asked Questions
6.1.
How do I compile a Java file?
6.2.
What command is used to run program?
6.3.
What is execution in Java?
6.4.
What is Javac command?
7.
Conclusion
Last Updated: Jun 15, 2025
Easy

How to Run Java Program?

Author Nikunj Goel
5 upvotes
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Java is relatively easy to learn and use. We will be learning step-by-step how to run Java program.

how to run java program

Java is an object-oriented language. It enables automatic memory management. It also has multi-threading. It has a vast standard library. It is open-source so you can use it for free. You can use it to make various web and mobile applications.

You write a Java program in the Java programming language. You can run a Java program on a Java Virtual Machine (JVM). JVM converts Java bytecode to machine code. Your Java programs are portable.

Now you will learn how to run Java programs in the command prompt.

Start with installing the Java Development Kit (JDK). Remember to set the JDK path in the system environment variables.

Why Learn to Run Java Programs Manually?

Learning to run Java programs manually is a crucial step for beginners to build a strong foundation in Java programming. It deepens their understanding of how Java works behind the scenes and helps them develop essential problem-solving skills. Here are key reasons why this practice is highly valuable:

1. Understanding the Compilation and Execution Process

When you manually run Java programs using commands like javac and java, you directly interact with the compilation and execution steps. This helps you understand how Java source code is first compiled into bytecode and then executed by the Java Virtual Machine (JVM). Grasping this process allows you to see the full lifecycle of a Java program and appreciate the role of the JVM in making Java platform-independent.

2. Troubleshooting and Debugging

Manual execution improves your ability to troubleshoot errors effectively. When running programs without an IDE, you see raw error messages and must fix issues like incorrect class names, wrong file paths, or compilation errors by yourself. This hands-on approach sharpens your debugging skills and helps you understand the root cause of problems rather than just relying on automated fixes provided by modern development tools.

3. No Dependency on IDEs

Relying solely on IDEs can create blind spots in your Java learning journey. Running Java manually from the command line teaches you how the language works independently of any tools. This skill is especially useful when working in limited environments, remote servers, or systems where IDEs are not available, giving you the confidence to manage Java programs in any setup.

4. Useful for Interviews and Exams

In many programming interviews, coding assessments, or academic exams, candidates are asked to write, compile, and run Java programs without using an IDE. Knowing the manual process can give you a significant edge in such situations. It shows that you not only know how to write Java code but also understand the complete build and execution process.

Steps to Run a Java Program

Here are the steps on how to run Java program:

Installing Java Development Kit (JDK)

Step 1 - You need to have JDK to run a Java program. So you can download the JDK from the Oracle's official site.

download the JDK from the Oracle's official site.

How to Create a Java File in Notepad

Step 2 -  First, you need a text editor. We are using Notepad here. 

Click on the "Start" button

Step 3 - Click on the "Start" button. Then type "Notepad" in your search bar. Now click on the Notepad app and open it.

Naming Convention

Step 4 - Write your Java program. Now save it with a .java extension. Here it is HelloWorld.java.

Write your Java program

Step 5 - Now open your terminal. Click on the "Start" button. Type "Terminal" in the search bar. Click on the Terminal app and open it. 
 

Step 6 - Go through to the directory having your Java program. Use the cd command. 

Use the cd command

How to Compile Java Program Using javac

Step 7 - Now, use the Javac command to compile your Java program. Here it is javac HelloWorld.java.
Once you are done compiling, it's time to run your Java program. Use the Java command to run it. Here it is java HelloWorld.

use the Javac command to compile your Java program

We successfully ran our Java code. Similarly, you can run any code you want.

There are many online Java compilers where you can run Java programs. You can also run your Java programs in an integrated development environment (IDE) such as EclipseIntelliJ IDEANetBeans etc.

As you have now understood how to run Java program, let’s get to know about various types of Java programs.

Types of Java Programs

There are many types of Java programs:

  1. Java Applets - These are small Java programs. They run within web browsers.
     
  2. Java Applications - These are standalone programs. They run on a computer without the need for a web browser.
     
  3. Java Servlets - They run on web servers. They handle HTTP requests and responses between a client and a server.
     
  4. JavaServer Pages (JSP) - It is a server-side technology. They help to create dynamic web pages using Java.
     
  5. JavaBeans - They are reusable components for making Java applications.

Security Considerations

Here are a few security considerations for to run Java program:

  1. Keep your Java runtime environment up to date with the latest security patches.
     
  2. Use secure coding best practices. 
     
  3. Use robust encryption algorithms. Use safe critical management practices to protect sensitive data.
     
  4. Implement proper access control methods. Ensure that only approved users can access sensitive data.
     
  5. Use secure communication protocols such as HTTPS. It will protect data transmitted over the network.
     
  6. Conduct regular security testing and scans.

Also see, Hashcode Method in Java

Frequently Asked Questions

How do I compile a Java file?

To compile a Java file, use the javac command followed by the name of the Java source file.

What command is used to run program?

To run a compiled Java program, use the java command followed by the name of the class that contains the main method.

What is execution in Java?

In Java, execution refers to the process of running a program. It involves:

  • Compilation: Code is translated into bytecode (machine-independent instructions).
  • JVM Execution: The Java Virtual Machine interprets or compiles (just-in-time) bytecode for the specific platform.

What is Javac command?

Javac is a Java compiler command used to transform Java source code (.java) into bytecode (.class) for execution on the Java Virtual Machine (JVM).

Conclusion

In this article, we learned how to run Java program. We also talked about the distinctions between Java and Javac commands. This article included step by step explanation of how to run Java program. Refer to Java articles to improve your understanding of Java programs.

To learn more about Data Structures and Algorithms, you can enroll in our course on DSA in Java.

Live masterclass