操作步骤:
编译运行环境的搭建
fedora下默认安装为GNU公司的JDK,如下所示
$java -version java version "1.7.0_25" OpenJDK Runtime Environment (fedora-2.3.10.4.fc19-i386) OpenJDK Server VM (build 23.7-b01, mixed mode)
而我们需要使用SUN公司的Java(这真的不是在广告),下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
下载完成以后配置如下: (比如我的jdk的路径是:~/jdk1.8.0_71/)
$ sudo alternatives --install /usr/bin/java java ~/jdk1.8.0_71/bin/java 500 $ sudo alternatives --install /usr/bin/javac javac ~/jdk1.8.0_71/bin/javac 500 $ sudo alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- *+ 1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.71-1.b15.fc23.x86_64/jre/bin/java 2 /home/zyoohv/jdk1.8.0_71/bin/java Enter to keep the current selection[+], or type selection number: 2
完成后输入以下命令查看配置是否成功:
$ java -version java version "1.8.0_71" Java(TM) SE Runtime Environment (build 1.8.0_71-b15) Java HotSpot(TM) 64-Bit Server VM (build 25.71-b15, mixed mode)
Java程序编辑、编译与运行
建立一个名字为HelloWorld.java的文件,并在其中输入如下代码:
public class HelloWorld{ public static void main(String[] args){ System.out.println("hello world !"); } }
在此文件目录下输入以下命令:
$ ls HelloWorld.java $ javac HelloWorld.java $ ls HelloWorld.class HelloWorld.java $ java HelloWorld hello world !