Downloading and Installing JDK

This page shows how to download and install the latest version of the Java Development Kit (JDK). Read the instructions carefully to set the "classpath" mentioned in Step 3. Once JDK has been installed, you can write a simple Java program using an editor such as notepad and run it from a command prompt. Alternatively, Java programs can be written using an Integrated Development Environment (IDE) such as NetBeans, described below.

2. How to Install JDK on Mac OS X

Step 1: Check if JDK has been Pre-Installed

To check if JDK has been installed, open a "Terminal" (Search "Terminal"; or Finder ⇒ Go ⇒ Utilities ⇒ Terminal) and issue this command:

javas - version
  • If a JDK version number is returned (e.g., JDK x.x.x), then JDK has already been installed. If the JDK version is prior to 1.8, proceed to Step 2 to install the latest JDK; otherwise, proceed to "Step 3: Write a Hello-world Java program".
  • If message "command not found" appears, JDK is NOT installed. Proceed to the "Step 2: Install JDK".
  • If message "To open javac, you need a Java runtime" appears, select "Install" and follow the instructions to install JDK. Then, proceed to "Step 3: Write a Hello-world Java program".

Step 2: Download JDK

  1. Goto Java SE download site @ .
  2. Under "Java Platform, Standard Edition" ⇒ "Java SE 11.0.{x}", where {x} denotes a fast running security-update number ⇒ Click the "Oracle JDK" "Download" button.
  3. Under "Java SE Development Kit 11.0.{x}" ⇒ Check "Accept License Agreement".
  4. Choose the JDK for your operating platform, i.e., MacOS. Download the DMG installer (e.g, jdk-11.0.{x}_osx-x64_bin.dmg  - about 166MB).

Step 3: Install JDK/JRE

  1. Double-click the downloaded Disk Image (DMG) file. Follow the screen instructions to install JDK/JRE.
  2. Eject the DMG file.
  3. To verify your installation, open a "Terminal" and issue these commands.
    // 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
    // Display the location of Java Runtime
    which java

Step 3: Write a Hello-World Java Program

  1. Create a directory called "myProject" under your home directory (Launch "Finder" ⇒ "Go" ⇒ "Home"; Select "File" ⇒ "New Folder" ⇒ "myProject").
    In Mac OS X, the home directory of the current user can be referenced as "~". Hence, this new directory can be referenced as "~/myProject".
  2. Use a programming text editor (such as Sublime Text or Atom) to input the following source code and save as "" under the directory "~/myProject".
    (If you use Mac OS X's default text editor "TextEdit" (NOT recommended), you need to open a new file ⇒ choose "Format" ⇒ "Make Plain Text" ⇒ Enter the source code ⇒ Save as "".)
     * My First Java program to say Hello
    public class Hello {   // Save as "" under "~/myProject"
       public static void main(String[] args) {
          System.out.println("Hello, world from Mac!");

Step 4: Compile and Run the Hello-World Java Program

  1. To compile the source code "", open a new "Terminal" ("Go" ⇒ "Utilities" ⇒ "Terminal") and issue these commands (as illustrated):
  2. // Change Directory (cd) to where "" resides
    cd ~/myProject
    // Check if "" exists using list (ls) command
    ls   ......
    // Compile "" using JDK compiler "javac"
    // If error message appears, correct your source code and re-compile
    // Check for the compiled output "Hello.class"
    Hello.class   ......
  1. To run the Hello-world, invoke the Java Runtime "java" as follows:
    java Hello
    Hello, world from Mac!