With the Java Development Kit (JDK) installed on your Mac, you can write and compile Java programs. Installing the JDK is very simple, and it will also install the NetBeans IDE in which you write code and compile it for testing.
Steps
Part 1 of 2: How to install the JDK

Step 1. Open the JDK download page
Launch a web browser and go to oracle.com/downloads/index.html.

Step 2. Download the JDK installation file
For this:
- Click Java.
- Click on Java SE.
- Click Download next to JDK 8 with NetBeans.
- Check the “Accept License Agreement” box, and then click the “Mac OS X” link at the top of the page. This is the most recent Java SDK release with the NetBeans IDE.

Step 3. Double click on the downloaded DMG file
The JDK Installer window will open.

Step 4. Follow the instructions on the screen to install the JDK
You will be prompted for an administrator password.

Step 5. Delete the DMG file when the installation is complete (if you like)
This will free up disk space because you will no longer need this file.
Part 2 of 2: How to Create Your First Program
Step 1. Launch NetBeans from the Applications folder
It is a Java development environment in which you can write and compile programs. 2.

3 Click File> New project.
A new project will be created in NetBeans. 4.

5 Select the Java category and the Java Application project.
NetBeans will be configured to generate Java files for this project. 6.

7 Give the project a name and click Finish.
For example, name the project "HelloMir". The code editor will open. 8.

9 Find the line “// TODO code application goes here”.
The program code will be located under this line. 10.


Step 11. Enter the program code on a new line
Press ⏎ Return at the end of the "// TODO code application goes here" line to go to a new line with the same indentation. Enter the following code:
System.out.println ("Hello world!");
Step 12. Click the Run Project button.
It looks like a green play button and is in the toolbar. 13.

14 Click the Output tab to see how the program works.
The result can be seen at the bottom of the screen after starting the project. 15.

16 Correct any errors.
If the project has no errors, you will see "Hello world!" In the "Output" tab. and the words “Build successful”. If there are errors in the project, you will see in which lines they occur. 17.


Step 18. Continue learning Java
Now that you have installed the JDK, continue learning Java programming. Read this article on how to write your first Java program.