Java Set Or Change The Path System Variable

What Is Java Path Environment Variable?

Within the Java environment, the path signifies an environmental setting employed by the operating system to pinpoint the locations of the javac and java directives. Essentially, the Java path variable eliminates the necessity of repeatedly inputting the complete path on the Command Line Interface (CLI) each time a program is executed. It essentially functions as a repository for a multitude of abbreviated references.

Why Is Java Path Required?

Setting the path is essential for utilizing tools like javac and java since these tools are not recognized by the operating system. Therefore, it is necessary to specify the location where the executable files are located.

Role of the JDK Bin Directory

Specifying the location of the bin directory, which houses all binary executable files, is essential. Setting this path enables the program to access all necessary files, such as the compiler or interpreter.

When Is Setting the Path Not Required?

Placing the Java source file in the JDK/bin folder eliminates the need to set the path as all tools will be accessible in the current location.

When Is Setting the Path Mandatory?

In case your Java file is located outside the JDK/bin directory, it becomes essential to configure the JDK path. Once the path is configured, it cannot be replaced.

Ways to Set the Java Path

In Java, you can establish the path in two ways:

-

  • Transitory

-

  • Persistent
  • 1. Setting Temporary Path of JDK in Windows

To set the temporary path of JDK, you need to follow the following steps:

  • Open the command prompt
  • Copy the path of the JDK/bin directory
  • Write in Command Prompt: set path=copied_path

For Example:

Example

set path=C:\Program Files\Java\jdk1.6.0_23\bin

In the image provided, prior to running the program, we temporarily configure the path.

2. Setting Permanent Path of JDK in Windows

To establish the permanent JDK path, you should adhere to these instructions:

  • Access the search box or use the Windows Key, enter Advanced System Settings, and select View Advanced System Settings. This action will launch the System Properties dialog box.

Another way to access the Advanced system settings is by right-clicking on the My Computer icon, selecting Properties, and then clicking on the Advanced tab.

To access the System Properties dialog box, you can click on Advanced and then proceed to click on the Environment Variables... button.

Within the Environment Variables dialog box, select the New button located in the System variables section to introduce a fresh system variable. It is important to specify both a Variable name and Variable value. Input JAVAHOME as the Variable name, and for the Variable value, enter the JDK path (commonly found at C:\Program Files\Java\jdk1.8.060). Proceed by clicking the OK button.

[visual]

Navigate to the System variables section and choose the Path variable. Proceed by clicking on the Edit button.

The dialog box for editing environment variables is displayed.

In the dialog box shown above, select the New button and enter %JAVA_HOME%\bin. Then, click OK.

Click on the OK button twice once more to proceed.

The configuration for the Java path in Windows has been successfully completed. This allows you to run Java programs from any drive on your system.

Setting Java Path in Linux OS

Configuring the path in a Linux operating system mirrors the process in Windows OS, with the distinction that Linux employs the export command instead of set. Below are the steps to set the path in a Linux OS:

Example

export PATH=$PATH:/home/jdk1.6.01/bin/

The Java Development Kit (JDK) has been successfully set up in the home directory located at Root (/home).

Input Required

This code uses input(). Please provide values below: