Wednesday, October 12, 2016

Confused between Open JDK & Oracle JDK ?


Variations of Java


There are three different editions of the Java Platform: Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME). This tutorial is focused on Java SE (Java Platform, Standard Edition).


There are two different Java SE packages that can be installed: the Java Runtime Environment (JRE) and the Java Development Kit (JDK). JRE is an implementation of the Java Virtual Machine (JVM), which allows you to run compiled Java applications and applets. JDK includes JRE and other software that is required for writing, developing, and compiling Java applications and applets.


There are also two different implementations of Java: OpenJDK and Oracle Java. Both implementations are based largely on the same code but OpenJDK, the reference implementation of Java, is fully open source while Oracle Java contains some proprietary code. Most Java applications will work fine with either but you should use whichever implementation your software calls for.


You may install various versions and releases of Java on a single system, but most people only need one installation. With that in mind, try to only install the version of Java that you need to run or develop your application(s).
If Oracle JDK is installed, output will be like below
[root@Ans.Master-~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

If it is Open jdk output will be like below

[root@Ans.Master-~]# java -version
java version "1.7.0_15"
OpenJDK Runtime Environment (IcedTea6 1.10pre) (7b15~pre1-0lucid1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)

How to remove OpenJDK and install Oracle JDK


# yum -y remove java*

Download Oracle JDK


wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm"
rpm -ivh jdk-7u79-linux-x64.rpm

[root@Ans.Master-~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Note that java will be installed into /usr/java and establish softlinks as follows:


[root@Ans.Master-~]# ll /usr/bin/java

lrwxrwxrwx. 1 root root 26 Oct 13 01:45 /usr/bin/java -> /usr/java/default/bin/java




Setup Global Environment Variables

We can easily set the environment variables using the export command as shown below.
export JAVA_HOME=/usr/java/jdk1.8.0_25/
export PATH=$PATH:$JAVA_HOME

JAVA_HOME will look for /bin/java so /usr/java/jdk1.8.0_25/ will be right path
But for $PATH we may need to point it to /usr/java/jdk1.8.0_25/bin..not sure if the above step is correct.
If you want JAVA_HOME to be set for every user on the system by default, add the previous line to the/etc/environment file. An easy way to append it to the file is to run this command:

  sudo sh -c "echo export JAVA_HOME=/usr/java/jdk1.7.0_79 >> /etc/environment"
OR
You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users
If you have multiple java installations in the system you need to make the preferred one as default 



Using Alternatives


The alternatives command, which manages default commands through symbolic links, can be used to select the default Java command.
To print the programs that provide the java command that are managed by alternatives, use this command:
sudo alternatives --config java
Here is an example of the output:
There are 5 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk1.8.0_60/jre/bin/java
   2           /usr/java/jdk1.7.0_79/jre/bin/java


Enter to keep the current selection[+], or type selection number: 

No comments:

Post a Comment