How to Run Java Program in Command Prompt CMD in Windows 11




In this blog post, I will give a detailed view of running the java program in command prompt CMD in your Windows 11 Operating System. 

1. Before the installation, we need to check whether java is installed or not. Click on the search icon and search for cmd. 

2. Once the command prompt opens, type java -version and press enter. If you see this kind of message which is displayed in the image below, then java is not installed in your Windows 11 Operating System. 

3. To install java, open a web browser of your choice and search for java JDK download. Click on the first link.

4. Once the link opens, scroll down and click on Windows. Then click the link next to x64 Installer. It will start to download. 

5. Once the download is complete, click on the exe file and minimize the browser. It will show a warning. Click on Yes.

6. In the installer window, click on Next.

7. This will be the location where java will be installed. If you want to change the location, then click on the Change option. I am going to leave it as default and click on Next.

8. It will start the installation process. It will display the installation successful message. Click Close on that window. 

9. Now, open File Explorer and go to the location where java is installed. Click on the java folder. 

10. To set the environment variable for java, click on the search icon and type Edit Environment and click on the search result. 

11. It will open this kind of window. Click on the path under system variables. Then, click on Edit. Here, you need to add the path. Go to the bin folder and copy the path. You can either double click or click on New. Then, paste the path. Press Enter. It will add the path. Then, click on Ok. Some applications need java home environment variables. 

12. To set a home environment variable, you need to click on the New under the user variable section. 

13. Here, you need to provide the variable name as JAVA_HOME and the variable value will be the folder. Just copy the path until the JDK folder and don’t go inside the bin folder. Paste that path in variable value. Click on Ok.

14. Once you have installed java and the environment variable, you can view java in the command line. Click on the search icon and type cmd. Once the command prompt window opens, type java -version and press enter. You will be able to see the latest version of java. 

15. To compile a java file, you need to use the javac command. Type javac -version and press enter. You will be able to see the javac version on the screen. 

16. To compile a raw java file, go to the location where you want to save the java file. Create a new folder and save all your java files in that folder. In that folder, right-click and click on the New Text Document. 

17. Since the file is in a text document, click on View, show, and then click on filename extensions. Rename this file as hello.java and press enter. It will show a warning. Click on yes.

18. I am going to open this file using Notepad. In the image, there is a simple java program available. Type this program in the notepad. You need to note down that the file name and class name should be the same. Once you have entered the code, copy the path in the file explorer. 

19. Open command and type cd and paste the path. Then, press enter.

20. To compile this file, type javac hello.java and press enter. 

21. Once the compilation is done, type java hello and press enter to get the output.

22. It will display the output. 

These are the steps for running a Java program in command prompt CMD in Windows 11 Operating System. 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*