|
第一步:下载jdk-7-linux-i586.tar.gz第二步:解压安装cd /usr/lib
sudo mkdir jvmcd {你的目录jdk压缩文件目录}sudo tar zxvf jdk-7-linux-i586.tar.gz -C /usr/lib/jvm
cd /usr/lib/jvm
sudo mv jdk1.7.0/ java-7-sun 第三步:修改环境变量vim ~/.bashrc(如果没有安装vim先执行:sudo apt-get install vim)export JAVA_HOME=/usr/lib/jvm/java-7-sun
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.{JAVA_HOME}/lib{JRE_HOME}/lib
export PATH=${JAVA_HOME}/binPATH加到末尾保存退出 source ~/.bashrc 第四步:配置默认JDK版本sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-sun/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-7-sun/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java-7-sun/bin/jar 300检查sudo update-alternatives --config java 第五步:查看java版本号命令行:java -version系统会列出java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode)第六步:测试[url=][/url]
package ubuntu.java.basic;
import java.util.*;
public class ArrayTest {
public static void main(String[] args) {
int[] a = new int[5];
for (int i=0;i<a.length;i++)
a = i*i;
System.out.println(Arrays.toString(a));
String[] b = {"hello","world","hi","you","good"};
System.out.println(Arrays.toString(b));
}
}
[url=][/url]
david@ubuntu:~$ cd JavaTrain
david@ubuntu:~/JavaTrain$ ls
david@ubuntu:~/JavaTrain$ ls
ArrayTest.java
david@ubuntu:~/JavaTrain$ javac -d . ArrayTest.java
david@ubuntu:~/JavaTrain$ ls
ArrayTest.java ubuntu
david@ubuntu:~/JavaTrain$ java ubuntu.java.basic.ArrayTest
[0, 1, 4, 9, 16]
[hello, world, hi, you, good]
|
|