CentOS 7
Sponsored Link

Install OpenJDK 82016/09/28

 
Install OpenJDK 8 to configure Java development environment.
[1] Install OpenJDK 8.
Oracle JDK includes compiler but compiler for OpenJDK 8 is included in openjdk-devel.
[root@dlp ~]#
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@dlp ~]#
cat > /etc/profile.d/java8.sh <<EOF
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar
EOF
[root@dlp ~]#
source /etc/profile.d/java8.sh
[2] If another version of JDK had been installed, change the default like follows.
[root@dlp ~]#
alternatives --config java


There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-1.b14.el7.x86_64/jre/bin/java
*+ 2           /usr/java/jdk1.8.0_71/jre/bin/java

# select the latest one
Enter to keep the current selection[+], or type selection number: 1
[3] Create a test program and make sure if it works normally.
[root@dlp ~]#
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);
    }
}

# compile

[root@dlp ~]#
javac day.java

# run

[root@dlp ~]#
java day

2016/9/30 19:46
Matched Content