1.1.1. CÀI ĐẶT JAVA DEVELOPMENT ENVIRONMENT
Cài đặt Java SE Development Kit (JDK)
a) Tải jdk-7-linux-x64.rpm từ địa chỉ http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.rpm hoặc và địa chỉ của Oracle (http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html)
b) Cài đặt JDK
[root@linux ~]#rpm -Uvh jdk-7-linux-x64.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
[root@linux ~]#vi /etc/profile
# add at the last line
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
[root@linux ~]#source /etc/profile
c) Test thử bằng cách tạo chương trình sau
[root@linux ~]#vi day.java
import java.util.Calendar;
class day {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DATE);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + minute);
}
}
[root@linux ~]#javac day.java # compile
[root@linux ~]#java day # execute
2011/7/30 21:7