Installing the "Java Development Kit" (JDK) on an OS X system allows you to create and compile Java applications. The JDK installation procedure is very simple and straightforward and also includes the development environment called "NetBeans". You can use the latter to write code in Java and compile it to be able to test its correctness.
Steps
Part 1 of 2: Install the JDK
Step 1. Go to the web page for downloading the JDK installation file
To do this, launch the internet browser of your choice, then use it to access the following URL: oracle.com/downloads/index.html.
Step 2. Download the JDK installation file
After loading the download page, you will need to download the correct installation file:
- Click the "Java" link.
- Select the "Java SE" item.
- Press the "Download" button next to "JDK 8 with NetBeans".
- Select the "Accept License Agreement" option, then click the "Mac OS X x64" link at the top of the page. This will download the latest version of the Java SDK and NetBeans development environment.
Step 3. Double-click the installation file you just downloaded
The file in question is in ".dmg" format; opening it, the installation interface will be displayed.
Step 4. To proceed with the installation of the JDK simply follow the instructions that appear on the screen
Before the installation procedure begins, you will be asked to provide the password of an administrator user on the computer.
Step 5. After the installation is complete, delete the DMG file (optional)
This will save disk space by deleting an item you no longer need, as the JDK is already installed on your system.
Part 2 of 2: Creating the First Program in Java
Step 1. Launch the NetBeans program from the "Applications" folder
This is the development environment for Java and allows you to write and compile code quickly and easily.
Step 2. Access the "File" menu, then choose the "New project" item
This will create a new project within the NetBeans development environment.
Step 3. Select the "Java" category, then select the "Java Application" option as the project type
In this way NetBeans will automatically create and configure the Java files needed for the chosen project.
Step 4. Name the project, then press the "Finish" button
In this example we will create the most famous of the test programs, so call it "HelloWorld". Once the development environment for the project is created, the code editor window will appear on the screen.
Step 5. Find the line "// TODO code application goes here"
Your program code should be placed after this comment line.
Step 6. Enter the Java code in a new line of text
To do this, press the Enter key after the comment line "// TODO code application goes here". This will create a new line that will have the same indentation as the previous one. At this point, you can type the following example code:
System.out.println ("Hello World!");
Step 7. Press the "Run Project" button to compile and run the project
It is a green "Play" button on the toolbar.
Step 8. Check the "Output" tab to see the result generated by running the program
This development environment pane appears at the bottom of the graphical interface once the program is run.
Step 9. Correct any errors present
If the code created contains no errors, you will see the strings "Hello World!" and "BUILD SUCCESSFUL" in the "Output" tab. Conversely, if the compiler found errors, you will see the line number of the code that generated them. If so, carefully analyze what you wrote, then correct the error.
Step 10. Deepen your Java knowledge
Now that the JDK is up and running you can unleash the Java programmer that's hidden inside you! Check out this article for more details and information on how to approach this powerful programming language as a beginner.