Javatpoint Logo
Javatpoint Logo

How to run a Java program in Windows 10

To run a java program in Windows 10, we need first to install Java and then set up the environment variables. To do this, follow the following steps-

How to install Java?

Step 1) Visit the oracle website and then click on download.

How to run a Java program in Windows 10

Step 2) Now, on the next page, click on Accept License Agreement and download the .exe file of JDK for windows.

How to run a Java program in Windows 10

Step 3) After downloading the file, start the installation process by clicking on the file.

Step 4) Keep clicking on next and don't alter any default setting.

After installation, we need to set the environment variables.


How to set up environment variables?

  • Open the control panel -> System and Security -> System -> Advanced System Settings. The following dialog box will appear.
How to run a Java program in Windows 10
  • Click on Environment Variables, go to system variables, and double click on Path.
How to run a Java program in Windows 10
  • Now add the path of the bin file present in the JRE folder and the JDK folder to the Path variable. The JRE and JDK are by default, present in the Java folder of Program Files.
How to run a Java program in Windows 10

The setup of the Java environment is complete.


How to run a Java program in Windows 10

To understand how to run a Java program in Windows 10, we will see a simple example of a Hello World program-

Step 1) Open a text editor and write the java code for the program. The program for Hello World is given below-

Step 2) Save this file with the .java extension. Make sure that the name of the file should be the same as that of the public class. If the file doesn't have any public class, we can save it with any name, but after compilation, a bytecode file will be generated with the name of the class containing the main method.

Step 3) Now, open the command prompt and open the directory in which we have saved our program by using the following command.


How to run a Java program in Windows 10

In this case, the directory is desktop.

Step 4) Now, run the following command to compile the Java program.


How to run a Java program in Windows 10

Step 5) After the code is compiled, it generates a bytecode file in the same folder having the .java file with a .class extension. This is the file which is executed by the JRE. To run this file, use the following command.


How to run a Java program in Windows 10

The output of the program will be seen on the command prompt.

This is how we can run a java program in Windows 10.


Next TopicJava Tutorial




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA