How to Run Java Program

How to run a Java program on a computer? We can run a Java program online or we can install Java virtual machine (JVM) in our computer system.

Run Java Program Online

There are several sites that allow us to run a Java program online. But online compilers have some limitations like we can’t work with files. It is not a good idea to always use them. Some sites are,, Codepad, CodeChef

Run Java Program in Windows by Installing Oracle JDK

Step1:- To Run Java programs in windows, Download the latest version of JDK from the Oracle website. Download .exe or .zip file.

Step2:- Install the downloaded .exe file. Or, for .zip file just extract it.

Now, JDK is installed on your system.

Just by installing software, its binary and library files are not available from other directories automatically. We must update environment variables with that software binary and binary file path. Now, let us update the environment variables.

Note:- If you are installing Java SE using .exe file which is only for Windows OS then the Oracle JDK offers “installers” (msi, rpm, deb, etc.) which not only place the JDK binaries in your system but also contain update rules and in some cases handle some common configurations like set common environmental variables (such as, JAVA_HOME in Windows) and establish file associations (such as, use java to launch .jar files). The Java SE Windows installer provides java.exe, javaw.exe, javac.exe, and jshell.exe commands in a system location so that users can run Java applications without needing to provide the path to the Oracle JDK’s installation folder. So, you can directly go to Step7 to check the installation is done correctly or not. No need to follow Step3 to Step6.

Step3:- Go to the Advanced system setting.

My Computer -> Properties -> Advanced System Settings

How to run Java program: Open properties
Windows advanced system settings

Step4:- Click on Environment variables.

Environment variables in Windows

Step5:- In this Window, in the User variables section or System variables section, we must create a Path.

create path for JDK

There are some differences between creating path variables in the user variables section vs system variables section. Learn more:- Different ways to set the Java path

Step6:- Add, Variable name = “path”

The Variable value is a location where Java is installed. By default, Java is installed in “C:\Program Files\Java\jdk\bin” Or, “C:\Program Files(x86)\Java\jdk\bin”.

In case, you have installed java at another location, then add that path.

image 3

Click on OK, save the settings. You have done.

Step7:- Now, check the installation is done correctly or not. Open, Command prompt (cmd) and type java -version

> java -version
java version "13.0.1" 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.1+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+8, mixed mode, sharing)

In order to make sure whether the compiler is set up, type javac in command prompt. You will see a list related to javac.

>  javac
Usage: javac <options> <source files>
where possible options include:

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *