Installing Java in Mac OS X
The first thing you need to do is download Java SE (Standard Edition) from Oracle. You may have Java installed in some form on your Mac already (probably the consumer version), but Java SE for Developers (known as the Java SDK) is the one to get.
You'll also need a IDE (Integrated Developer Environment), and Oracle has a great one called NetBeans. We'll install both the Java SKD and NetBeans at the same time.
- Open Safari and head to Oracle's Downloads page. Click on Java SE.
- Click on the Download icon under NetBeans with JDK 8. You'll want a programming environment, and Netbeans is a good one. The JDK 8 will come alongside it and it handles the install for you.
- Click on Accept License Agreement and click the Download link next to Mac OS X. The DMG file will be saved into your Downloads folder.
- Open the download file (ours is "NetBeans 8.1 wtih JDK 9 Update 73") and follow the installation instructions.
- Open System Preferences and click on Java then About. Check that Version 8 Update 74 (or later) is installed. Alternatively open Terminal and enter "java -version."
You should now have Java and NetBeans installed in OS X. NetBeans is where you'll be creating most of your programs, so let's take a look at it.
Create HelloWorld in Java with NetBeans
The next step is to open NetBeans in OS X and create your first program. Tradition has it that the first program you create in any language should print "Hello World!" on the screen. Here's how to create HelloWorld in NetBeans:
- Open the Applications folder and launch NetBeans 8.1.
- Choose File > New Project.
- Ensure Java is selected in Categories and Java Application in Projects. Click Next.
- Enter "HelloWorld" in the Project Name field. Ensure "Create Main Class" is highlighted and click Finish.
- You should see the contents of HelloWorld.java in the main window. If not, use the Projects window on the left and locate HelloWorld.java (under Source Packages).
- Locate the code marked "// TODO code application logic here". Underneath this add a line that says "System.out.println("Hellod!");". Ensure this line of code is lined up with the "// TODO..." line above. See the image for exact positioning.
- Choose File > Save.
- Click the green Run Project icon in the Toolbar.
In the Output window at the bottom you should see the following:
BUILD SUCCESSFUL (total time: 0 seconds)
Sign up for MIS Asia eNewsletters.