To answer your last question, on your operating system there is something called “PATH”. It is a user- or systemwide variable that dictates where to look for programs. It basically is a list of directories, often separated by “:”
Further reading: https://www.java.com/en/download/help/path.html (this may have Java references but still applies)