Java and JavaScript are completely different
It’s most unfortunate that these two languages have such similar names, as it makes them so easy to confuse.
Although influenced by Java, JavaScript is an event-driven language used extensively on webpages, which is normally built into your browser and other apps which support it. Think of it as a type of AppleScript which runs in web pages.
In Safari, you control JavaScript in the Security section of its Preferences dialog. Unless you have good reasons to disable it, it is best enabled, as many websites stop working if your browser doesn’t handle its scripts. It has also been built into other apps as a scripting language: again, their support is built-in, and there are no separate components to install or keep updated.
Java is normally installed as an add-in to macOS, and supports the running of Java apps via web pages and as standalone apps on your Mac. Safari’s controls over Java are quite separate, and part of the Websites section of its Preferences. By default, Safari and other browsers will not run Java automatically, but at least ask you if you want to enable it for that site, when it’s installed.
Apple and Oracle Java
Apple used, a long time ago, to bundle Java with OS X, and still provides a separate installer if you need to support Java 6. The only recent apps which require you to install Apple’s old Java support are most of those in Adobe Creative Studio 6 and earlier, which will not run without it. Apple’s Java 6 runtime is available from here.
If you want to run any modern Java software, including that provided over the internet, then you should install the current version from Oracle here.
Apple’s Java 6 and Oracle’s Java 9 can peacefully coexist if you use apps requiring both versions, and Apple has now confirmed that its existing Java 6 installer is good for High Sierra too.
Which version is installed?
If you have a modern Oracle version of Java, you can tell from the command line by typing
java -version
in Terminal. Currently, this should produce a response such as
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
If you merely get an error, indicating that the command was not found, this implies that you don’t have any version of Java installed.
Modern implementations of Java also install their own pane in System Preferences, to control Java’s settings. If you don’t have that pane, you don’t have a proper installation of Java; if you do, it will tell you which version is installed, and should also help you bring it up to date as needed.
Should you have Java installed?
There is nothing inherently insecure or dangerous about having Java installed on your Mac. However, if you don’t use it, it is another thing to clutter up your Mac. If you do have it installed, you should also ensure that your browsers are properly configured so that access to it is restricted, and you must keep it up to date.
Java continues to develop, and vulnerabilities are found in current and older versions which need to be fixed in updates. If you were to have an old, vulnerable version of Java 8 installed, and left it open for any website to use, you could end up running Java malware, which would be seriously bad news. Although not likely, you should not expose your Mac to that risk.
If you are going to use it, ensure that you keep it up to date.
(Updated 31 October 2017 confirming High Sierra compatibility for Apple Java 6 runtime.)