You will need Java installed if you want to:
Install Homebrew if it is not installed already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then, install the latest version of Java:
brew install openjdk
Open launchpad by pressing F4 and type in terminal.
Alternatively, you could also do it with Spotlight by pressing Command + Space.
Next, type in the following command.
Most newer macs ship Java 8, so you should see something like this.
If not, you might find an older version of java.
Some macs do not ship java by default, and you will be prompted to install it from java.com. You can ignore it and continue to the next step.
This process is not necessary, but if you would like to uninstall an older version of java that came with your mac, for example, Java 5 or 6, you can use the Java Uninstall Tool provided by Oracle to help uninstall them.
To download the Java installer, go here
For better compatibility pick Version 8 of Java and the HotSpot JVM, and then download the .pkg installer for the JRE.
Open the installer that you just downloaded.
Click on the Continue button until you reach the Installation Type page. Here, you can change the installation disk. It is recommended to install java on the same disk as your operating system.
While installing, you should see an alert box. You will need administrator privileges to install. Type in an Administrator's username and password to continue.
If you've done everything correctly, you should see something like this
Finish the installation, choose whether to delete the installer or not and then go back to Step 1 to verify that Java was installed correctly.