Some Mac users may need to install Java into mac OS Sierra or Mac OS High Sierra.
Typically the need for Java is for specific app usage, particular app compatibility, or for developers, and it’s worth mentioning that most Mac users won’t need to bother installing Java at all.
Installing a JRE from Oracle will not update If you have not yet installed Apple's Java OS X 2012-006 update, then you are still using a version of Apple Java 6 that includes the plug-in and the Java Preferences app.
So double-check to make sure you installed the JDK and not just the JRE.Install the JDK 7 and this problem will solve itself.For those that do need Java however, you will find it’s easy to get onto the latest versions of Mac OS.As you may know by now, Mac OS no longer ships with Java preinstalled, so you’ll need to download and install java on your own if you need it in Mac OS 10.13 or 10.12.There can be multiple JDKs installed on a system, as many as you wish.
When launching a Java application through the command line, the system uses the default JDK.
Depending on your processor, the downloaded file has one of the following names: If you have not yet installed Apple's Java OS X 2012-006 update, then you are still using a version of Apple Java 6 that includes the plug-in and the Java Preferences app.
See "Note for Users of OS X that Include Apple Java 6 Plug-in".
It is possible for the version of the JRE to be different than the version of the JDK.
So this is the line causing the problem every time I opened a new terminal window. You still need to follow what @aleroot said, but if that doesn't work for you, check the .bash_profile (or .bashrc) setting file to see if you've previously exported any java version.
Be sure to get the Java Development Kit (JDK) which includes compilers and stuff like that, rather than just the Java Runtime Environment (JRE) .