1. Before installing the JDK, check whether the JDK is already installed on your computer.

Open the terminal, type Java -version, and press Enter. The following figure shows that the Java environment, JDK version 8, is installed. If this is the version you need, go straight to Step 4, Configuring the Java development environment.

2, If you do not have JDK installed, go to the official website to download the required:

Click this link to enter

3. JDK installation. Installing the JDK for MAC is very simple, and the next step is ok.

4. Configure the Java development environment

Default installation directory for the MAC/Library/Java/JavaVirtualMachines /

Use the shortcut command + Shift + G to go to the JavaVirtualMachines directory as shown below:

Next – open the terminal directly and type: CD/Library/Java/JavaVirtualMachines jdk1.8.0 _261. JDK/Contents/Home/then enter into or you can use shortcuts, OpenInTerminal – Lite 】 【 amway for everyone, Link as follows:

Enter sudo -i vi /etc/.bash_profile and press Enter.

Enter your computer password and press Enter. On the page that pops up, press I to start typing the following

JAVA_HOME = / Library/Java/JavaVirtualMachines jdk1.8.0 _101. JDK/Contents/Home / CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar PATH=$JAVA_HOME/bin:$PATH: export JAVA_HOME export CLASSPATH export PATHCopy the code

Press Esc to exit the editing mode and enter :wq to save the configuration

Type source /etc/.bash_profile and press Enter for the configuration to take effect

Enter Java and Javac respectively on the terminal. If the following page is displayed, the configuration is successful.

5. Write a program and execute it

You can start by writing a program with a text editor and saving it as a Java file with a. Java suffix

Open your text editor and type the following code to save as helloworld.java:

 

class HelloWorld{ static void main (String args[]){ System.out.println("HelloWorld"); }}Copy the code

  

Find the location where the Java file is saved and enter it using a terminal command

Then type javac helloworld.java

Java HelloWorld (note that you don’t need the suffix. Java)

And then the screen says “HelloWorld”

Environment configuration successful!

Next is to download the IDE for learning and development, good luck ~~