JDK 安装
下载安装
-
下载JDK
从oracle官方网站下载并安装JDK. -
下载使用文档
从oracle官方网站下载使用帮助文档. -
安装库源文件
源文件位于安装目录的 /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/lib/src.zip
查看已安装JDK
mac-abeen:~ abeen$ /usr/libexec/java_home -V
//已安装JDK
Matching Java Virtual Machines (3):
9.0.4, x86_64: "Java SE 9.0.4" /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
1.8.0_66, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
1.8.0_65, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
//默认使用JDK
/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
查看版本
mac-abeen:~ abeen$ java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
mac-abeen:~ abeen$ javac -version
javac 9.0.4
Hello World
创建Welcome.java源文件
mac-abeen:java abeen$
/**
* This program dispalys Hello World
* @version 1.0
* @author ABeen
* */
public class Welcome
{
public static void main(String[] args)
{
String greeting = "Hello World!";
System.out.println(greeting);
}
}
编译并执行
mac-abeen:java abeen$ javac Welcome.java
mac-abeen:java abeen$ java Welcome
Hello World!