To define the path in Java, the “PATH” environment variable must be configured. The “PATH” environment variable specifies the directories containing the Java runtime environment (JRE) and Java Development Kit (JDK) executables.
Here’s how you can set the path in Java:
1. Determine the Java installation directory:
- For JDK: If you have installed the JDK, the installation directory will be the location where you installed it. For example, “C:\Program Files\Java\jdk1.8.0_271”.
- For JRE: If you have only installed the JRE, the installation directory will be similar to the JDK but without the “jdk” part in the path.
2. Set the “PATH” environment variable:
- Right click on My Computer/ This PC icon.
- Search for “System” or “System Properties” and open it.
- Click on “Advanced system settings” (or similar) to open the System Properties window.
- In the System Properties window, click on the “Environment Variables” button.
- In the Environment Variables window, under “System variables,” find the “Path” variable and select it.
- Click on the “Edit” button to modify the “Path” variable.
- In the Edit Environment Variable window, add the path to the bin directory of your JDK or JRE installation. Separate multiple paths with a semicolon (;).
- For example, if your JDK installation directory is “C:\Program Files\Java\jdk1.8.0_271\bin”, add this path at the end of the “Path” variable.
- Click “OK” to save the changes.
3. Verify the path configuration:
- Open a new command prompt or terminal window.
- Type “java -version” and press Enter. It should display the version information of your installed Java runtime environment or Java Development Kit.
You may execute Java-related commands and programmes from any command prompt or terminal by specifying the path correctly.