You are here
Home > java > Core Java >

How to run a Java program in Windows 10+ ?

How to run a Java program in Windows 10+? : Java Setup An essential target as a new learner of a programming language is running your first program. Java is a popular and flexible programming language known for its portability and wide range of applications. To run a Java program, we need to set up our development environment, write the code, and then execute it. In this article ”How to run a Java program in Windows 10+ ?”, we are going to discuss a summary of the complete steps involved in running our very first Java program.

If you are going to learn/work on Java, your first step is to install java on your computer/laptop and check whether you have complete environment to start running your Java Programs or not. Here, we will test our java environment in Windows 10+ platform. So the title of this article is ‘How to run a Java program in Windows 10+ ?’.

How to Download Java?

First step to java Setup is to make sure you have java installed in your system. Latest version of Java as a .exe file can be downloaded from Oracle Java Website. From Java 11 onward, we can just download .zip file.

How to install Java? 

Java can be installed on Windows like any other program (.exe) simply by clicking on the exe file after downloading it.

Note : Java 11 version onward, It’s not mandatory to do installation process. We just need to download zip file from Oracle site as per your operating system & unzip it like eclipse. We can also install it as before. Java 11 has only JDK to install, no need to install JRE separately. JRE automatically gets installed with JDK.

What is LTS (Long term Support ) version?

For product releases after Java SE 8, Oracle will designate a release, every three years, as a Long-Term-Support (LTS) release. Java SE 11 is an LTS release. Once a new feature release is available, any previous non‑LTS release will be considered superseded. For example, Java SE 9 was a non‑LTS release and immediately superseded by Java SE 10 (also non‑LTS). Java SE 10 in turn is immediately superseded by Java SE 11. However, Java SE 11 is an LTS release, and therefore Oracle Customers will receive Oracle Premier Support and also periodic update releases, even though Java SE 12 was released.

How to run a Java program in Windows 10?

Before running a Java program there are some primary steps to create runnable environment first. Let’s complete them step by step:

How to set Java Environment Variable in your system?

If you want to compile & run your Java Program anywhere from command line, you need to set environment variables. In order to set environment variable in Windows 10+ platform, search for “Computer” and then select “This PC” option and then click on “properties”. Now, from property window, select “ADVANCED SYSTEM SETTINGS”. In System Properties window click on “Environment Variables”. Now you will see Environment Variables window where you will find two sections : ‘User Variables’ and ‘System Variables’.

Further, in ‘User Variables’ section, click on ‘New” button. Fill below information to set JAVA_HOME variable as per your installed Java version. Please remember that the field Variable name must be JAVA_HOME, and the field Variable value must point to JDK’s installation directory on your computer. Finally, click on OK to close this dialog.

How to Set JAVA_HOME

Furthermore, come back to the Environment Variables window, look for a variable called ‘Path’ under the System Variables list. Now click on ‘Edit’. Now, In the Edit environment variable dialog click on ‘New” and insert the path of your java installation directory till the bin folder to the end of the field Variable value as following : C:\Program Files\Java\jdk-13.0.2\bin

How to run a Java program in Windows 10+? : Java Setup

Click on OK three times to close all the dialogs.

How to Check if Java is Installed ?

To check if Java installed properly or not, open COMMAND prompt in windows OS. To open command prompt write “CMD” in run command and then hit enter. In command prompt window
write “java -version“.
If Java installed properly and all environment variables are ok, it will show version number of Installed JDK with the message as below.
UsersJBI>java -version

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

​If there is any problem while installing or in setting environment variable output could be like below:

'java' is not recognized as an internal or external command, operable program or batch file.

If the above error occurs, it means that the java path is not set in your system.

How to set path in Windows system from command prompt?

In order to set the path, open command prompt (cmd). Now, go to the place where you have installed java on your system and locate the bin directory. Then copy the complete path and write it in the command like below.

set path=C:\Program Files\Java\jdk1.8.0_124\bin

How to write First Java Program ?

Here we will learn to write first Java program. Let’s start our first Java program with “Hello World”. But we will just change it to “Hello Java Tech Online!”. If everything till now is ok, our fist program will show the correct output. For example, Let’s open a text editor and write below program.

public class FirstProgram {  
  public static void main(String args[]) {   
     System.out.println("Hello Java Tech Online!");    

Now save the file with name ““. Once file saved open the command prompt and change directory where file is saved with cd command. And fire “JAVAC” command that we use to compile the java code as below.

♦ UsersJTO>cd C:JTO

♦ C:JTO>javac 

If java file compiles properly, compiler will create a class file for the java source file. It will create it either in same location or other depending on package declaration. Since there is no package declaration in the code, therefore compiler will create the .class file in the same folder where .java file exists.

You can also use IDE like Eclipse to run the java program. We have covered that part in other article Eclipse IDE tutorial and it’s keyboard shortcuts. For the sake of simplicity, we have only used text editor and command prompt (or terminal) for this tutorial.

How to Run Java Program after java Setup?

Since java file compiled with “JAVAC” command. Therefore, we can now run the program. In order to run the above program, execute “JAVA” run command as given below.

♦ C:JTO>java FirstProgram
Output : Hello Java Tech Online!

Note*: here we are using only the class file name and not extension(.class). Here we have done with Creating and running our first Java program within our article ‘How to run a Java program in Windows 10+ ?’.


4 thoughts on “How to run a Java program in Windows 10+ ?

  1. Thanks for sharing this detailed guide on how to run a Java program in Windows 10+! I’ve been struggling to get Java working on my Windows 10 machine for a while now, and your steps were incredibly helpful. I particularly appreciated the section on installing the Java Development Kit, as I was unaware of that requirement. Can’t wait to try out your method and start coding in Java!

  2. Thank you for sharing this helpful guide on how to run a Java program in Windows 10+. I’ve been struggling to get Java running on my new laptop, and your step-by-step instructions were easy to follow and worked like a charm. I’m so glad I found this post – it’s really appreciated!

  3. Thanks for sharing this helpful article! I’ve been struggling to run my Java programs on Windows 10, and your instructions were easy to follow and worked like a charm. Greatly appreciate the time you took to write and share this post!

Leave a Reply