Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Steps to Run a Java Program
Types of Java Programs
Security Considerations
Frequently Asked Questions
How do I compile a Java file?
What command is used to run program?
What is execution in Java?
What is Javac command?
Last Updated: Jun 4, 2024

How to Run Java Program?

Author Nikunj Goel
Crack Google SDE interview : Essential projects
Saurav Prateek
SDE-2 @
20 Jun, 2024 @ 01:30 PM


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.

Steps to Run a Java Program

Here are the steps on how to run Java program:

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

jdk download

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


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

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

running 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 cd command

Step 7 - Now, use the Javac command to compile your Java program. Here it is javac
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.

cmd prompt

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.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

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).


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.

Previous article
Thread Safe in Java
Next article
Difference Between this and super in Java
Live masterclass