Java Compiler on Mac OS X

July 28, 2020

1. Which Version(s) of Java Compiler Do I Have On My Mac?

Open a Terminal window as follows:

       Finder
       -> Applications [task bar lower right]
       -> Utilities
       -> Terminal (or Terminal.app)
By now, you are talking to the OSX Unix operating system. Type in the following command to the Unix prompt:
       java -version
and see what you get. It will tell you which version of Java your system is actually using if your computer has multiple versions of Java installed on it. It will most likely show the latest version available on your computer. In my case I see "1.8.0_121".

This is not the latest version available from Oracle at this writing, which is "14.0.2". So, I will install the latest version available today as you will see in the next section below. If you already have the latest version on your computer, you may skip to Section 3 below. Actually, if you have a version such as "1.8.x" for any number "x", or a newer version, you should be fine for this class.

2. Installing the Latest Version of Java Compiler

If you want to install the latest version available from Oracle, you may do so as follows:
  1. Go to the Java SE Downloads page. I see 'Java SE 14.0.2' which is the latest version available at the time of this writing. If you see a newer version, use the latest.
  2. Click on JDK Download.
  3. Download jdk-14.0.2_osx-x64_bin.dmg for MacOS into a folder of your choice on your computer. You will need to accept the license agreement to download the file. Double click on the file to install it. This will show a .pkg file.
  4. Double click on the package and follow the prompts. Just accept defaults along the way (and agree to the license terms).
  5. Now, open a Terminal window as before, and try the 'java -version' command once more. It will show something like:
  6. That's it!

3. Verifying the Installation

Let's see if the Java compiler that you just installed works or not.
  1. Download Hello.java into a folder of your choice.
  2. Open a Terminal window and move into the folder where Hello.java is located. (If you don't know how to navigate through the system using a Terminal window, you will have to learn some Unix commands. You can do that using Unix Lab.
  3. In that folder, try the "javac" command to compile Hello.java like this:
         javac Hello.java
       
  4. Now, try the "java" command to run Hello like this:
         java Hello
       
    If it went well, you will see the result like this:
         Welcome to CS!!!
         Let's have some fun.
       
  5. That's it!