1. Overview
As Java developers, we always talk about Java "bin" directory set up on the "Path" environment variable immediately after the Java installation.
But, did we ever realize why we need that setup.
In this article, let's understand why we need this setup.
2. Content
2.1. Why do we need to set up?
Let's take a look at some of the Windows applications like "Notepad" and "Calculator", which can be opened from any location on Windows., not just from the installed location. How is that happening?
This is because the locations of the executable files for "Notepad" and "Calculator" applications are already included on the "Path" environment variable by default.
- Executable file "notepad.exe" is available on Windows root
- Executable file "calc.exe" is available on the "system32" folder of Windows root
And both these locations are already included on the Path environment variable by default, which makes it easy for us to invoke these applications from anywhere on the operating system.
In a similar fashion, once the Java is installed, we get a bunch of executable files inside the "bin" folder, which includes Java compiler for compilation, JVM for execution, and few others.
Otherwise, we have to get into the "bin" folder every time we need to invoke the executables like a compiler, as they reside inside the "bin" folder.
And, if we try to execute Java commands outside the "bin" folder, the system gives us an error message.
The only solution to avoid this is by including the "bin" location on the "Path" variable, which makes the compiler and JVM available all through the operating system so that they can be invoked from any location on the operating system.
This setup will allow us to run Java commands from anywhere on the operating system, nothing but the system.
2.2. How to set up the Path environment variable?
First, check the location of the "bin" directory from the installed Java location on your machine.
Then, open system environment variables, and add the location to the "Path" environment variable.
After the setup, we have to make sure that the Java is available across the system by running the Java commands from multiple locations on the system.
Refer to the below video for more details.
https://randomcodez.com/how-to-setup-path-environment-variable
NOTE: Java installer should create a location for the Java path on Windows and add the "bin" directory location to the "Path" environment variable automatically. In case if it is not added or somehow deleted, we have to set up this to avoid any Java errors.
3. Conclusion
We should have a clear understanding of why we need to set up the Path environment variable.