On some Mac systems (earlier than Mac OS X 10.7), JDK has been pre-installed. To check if JDK has been installed, open a Terminal (Spotlight Search for Terminal; or use Finder ⇒ Go ⇒ Utilities ⇒ Terminal) and issue this command:
javac -version
If a JDK version number is displayed (e.g., JDK x.x.x), then JDK was already installed on your Mac. If the JDK version is earlier than 1.8, proceed to Step 2 to install a later JDK; otherwise, proceed to Step 4: Verify installation.
If the message command not found is displayed, JDK is NOT installed. Proceed to the Step 2: Install JDK.
If the message To open javac, you need a Java runtime is displayed, select Install and follow the instructions to install the JDK. Then, proceed to Step 4: Verify installation.
Point your browser to the Java SE download site. Under Java Platform, Standard Edition select Java SE 11.0.1(LTS) OR Java SE 8u191 / Java SE 8u192. Click the JDK Download button.
Check Accept License Agreement.
Choose your operating platform, i.e., MacOS. Download the installer (file with extension .dmg).
Double-click the downloaded disk image (.dmg) file.
Follow the provided instructions to install JDK/JRE.
Eject the DMG file.
// Display the JDK version
javac -version
javac 11.0.{x}
// Display the JRE version
java -version
java version "11.0.{x}"
......
// Display the location of Java Compiler
which javac
/usr/bin/javac
// Display the location of Java Runtime
which java
/usr/bin/java