Now, locate the path of the JDK on your computer, and set the path to the JDK via the following command line. You can check if your Java program file is present in this directory by using the Dir command too. We will make use of the ‘cd’ command to change the operating directory on the Command Prompt to the one where your Java program is stored. Now, open the Command Prompt and run it as administrator. This file is to be saved in a separate folder in whichever destination you prefer. java and from File type, select ‘All Files’. In order to do so, name your file as ‘SampleFile.java’ (You can name the file anything, as long as the file extension is. Users should make sure of proper indentations since neither Notepad nor Word would help you with that, and also that the file is saved as a ‘.java’ file and not as a ‘.txt’ file. For example, we’ll be writing a simple code that gives the output “Hello World!”. For this purpose, you can use either MS Word or Notepad. How to run a Java program using Command Prompt #įirst things first, you will have to write the code that you want to run and save that as a Java executable file. You’ll have to have the JDK downloaded and installed on your computer before you can begin the process. You can download the Java Development Kit (JDK), which runs across platforms as the most important toolkit to writing Java code, from the Oracle website. As a prerequisite, you’re required to download a dedicated Java compiler on your computer. The process is the same for Mac as it is for Windows. While we will be talking exclusively about Command Prompt, this functionality exists for its macOS counterpart, Terminal, too.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |