How to Set Path in CMD for Java
Setting Path in Command Prompt for Java
How to Set Path in CMD for Java
Setting the path in the command prompt (cmd) for Java is essential to allow your system to locate the Java Development Kit (JDK) or Java Runtime Environment (JRE) executables from any directory. By configuring the path, you enable the cmd to recognize Java commands like ‘java’ or ‘javac’ without having to specify the complete file path each time. This makes it more convenient and efficient to run Java programs or compile Java files straight from the command prompt. Additionally, setting the path globally ensures that Java commands can be executed from any location within the cmd, streamlining the development and execution processes.
To Download Our Brochure: https://www.justacademy.co/download-brochure-for-free
Message us for more information: +91 9987184296
1 - Begin by opening Command Prompt: Press the Windows key, type “cmd,” and press Enter.
2) Check if Java is already installed: Type “java version” and press Enter. If Java is installed, the version will be displayed.
3) If Java is not installed, download and install the latest Java Development Kit (JDK) from the official Oracle website.
4) After installing JDK, navigate to the bin directory in the JDK installation folder.
5) Right click on the address bar in the File Explorer and select ‘Copy address as text’.
6) Type ‘cd’ in the Command Prompt followed by a space, then right click to paste the copied path.
7) Press Enter to change the directory to the JDK bin folder in Command Prompt.
8) Verify that you are in the correct directory by typing ‘dir’ and pressing Enter to see the list of files in the directory.
9) Once in the JDK bin directory, you can now compile and run Java programs using Command Prompt.
10) To compile a Java program, type ‘javac’ followed by the filename with the .java extension (e.g., javac MyProgram.java) and press Enter.
11) If there are no errors, a new file with a .class extension will be created in the same directory.
12) To run the compiled Java program, type ‘java’ followed by the class name (without the .class extension) and press Enter (e.g., java MyProgram).
13) Ensure that the JDK bin directory is added to the system PATH to run Java commands from any directory in Command Prompt.
14) To permanently set the PATH environment variable, right click on ‘This PC’ or ‘Computer’ and select ‘Properties’.
15) In the System Properties window, click on ‘Advanced system settings’, then click the ‘Environment Variables’ button.
16) In the Environment Variables window, under System variables, find the ‘Path’ variable and click ‘Edit’.
17) Click ‘New’ and paste the path to the JDK bin directory copied earlier. Click ‘OK’ to save the changes.
18) Close and reopen Command Prompt to apply the changes and now you can run Java commands from any directory.
Browse our course links : https://www.justacademy.co/all-courses
To Join our FREE DEMO Session: Click Here
Contact Us for more info:
- Message us on Whatsapp: +91 9987184296
- Email id: info@justacademy.co