Posted on 1 Comment

What is the difference between JRE, JVM and JDK?

JDK (Java Development Kit)

Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc…

Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method.

You need JDK, if at all you want to write your own programs, and to compile the m. For running java programs, JRE is sufficient.

JRE is targeted for execution of Java files

i.e. JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.

JDK is mainly targeted for java development. I.e. You can create a Java file (with the help of Java packages), compile a Java file and run a java file

JRE (Java Runtime Environment)

Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system

The Java Virtual Machine provides a platform-independent way of executing code; programmers can concentrate on writing software, without having to be concerned with how or where it will run.

If u just want to run applets (ex: Online Yahoo games or puzzles), JRE needs to be installed on the machine.

JVM (Java Virtual Machine)

As we all aware when we compile a Java file, output is not an ‘exe’ but it’s a ‘.class’ file. ‘.class’ file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… JVM is platform dependent.

The JVM is called “virtual” because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs.

There are different JVM implementations are there. These may differ in things like performance, reliability, speed, etc. These implementations will differ in those areas where Java specification doesn’t mention how to implement the features, like how the garbage collection process works is JVM dependent, Java spec doesn’t define any specific way to do this.

 

Posted on

Install Sun/Oracle Java JDK/JRE 7 on Linux Fedora, CentOS/RHEL

This is a guide about how to Install Sun/Oracle Java JDK and JRE 7 update 2 (7u2) on Fedora 16, Fedora 15, Fedora 14, Fedora 13, Fedora 12, CentOS 6.1/6/5.7, Red Hat (RHEL) 6.1/6/5.7.

If you’re looking instruction for Sun/Oracle Java JDK/JRE version 6 installation on Fedora 16/15, CentOS/Red Hat (RHEL) 6.1/5.7, please check this guide.

What’s new in Sun/Oracle Java 7

  • VM
    • Compressed 64-bit object pointers
    • Garbage-First GC (G1)
    • JSR 292: VM support for non-Java languages (InvokeDynamic)
  • Lang
    • JSR 294: Language and VM support for modular programming
    • JSR 308: Annotations on Java types
    • JSR TBD: Small language enhancements (Project Coin)
    • JSR TBD: Project Lambda
  • Core
    • Modularization (Project Jigsaw)
    • Upgrade class-loader architecture
    • Method to close a URLClassLoader
    • Unicode 5.1
    • Concurrency and collections updates (jsr166y)
    • JSR 203: More new I/O APIs for the Java platform (NIO.2)
    • SCTP (Stream Control Transmission Protocol)
    • SDP (Sockets Direct Protocol)
    • Elliptic-curve cryptography (ECC)
  • Client
    • XRender pipeline for Java 2D
    • Forward-port 6u10 deployment features
    • Create new platform APIs for 6u10 graphics features
    • Nimbus look-and-feel for Swing
    • Swing JLayer component
  • Web
    • Update the XML stack

Read full info from here.

If you don’t know what is the difference between JRE, JVM and JDK, read here.

Install Sun/Oracle Java JDK/JRE 7u2 on Fedora 16/15/14/13/12, CentOS 6.1/6/5.7, Red Hat (RHEL) 6.1/6/5.7

1. Download Sun/Oracle Java JDK/JRE 7u2 32-bit/64-bit RPM packages

Download Sun/Oracle Java 7u2 from here http://www.oracle.com/technetwork/java/javase/downloads/index.html. Select rpm package (jdk-7u2-linux-i586.rpm, jdk-7u2-linux-x64.rpm, jre-7u2-linux-i586.rpm or jre-7u2-linux-x64.rpm).

2. Change to root user.

sudo -i
## OR ##
su -

3. Install Java JDK or JRE package

## JDK 32-bit ##
rpm -Uvh /path/to/binary/jdk-7u2-linux-i586.rpm

## JDK 64-bit ##
rpm -Uvh /path/to/binary/jdk-7u2-linux-x64.rpm

## JRE 32-bit ##
rpm -Uvh /path/to/binary/jre-7u2-linux-i586.rpm

## JRE 64-bit ##
rpm -Uvh /path/to/binary/jre-7u2-linux-x64.rpm

4a. Install Sun/Oracle JDK java, javaws, libjavaplugin.so (for Firefox/Mozilla) and javac with alternatives –install command

Use Java JDK latest version (/usr/java/latest)

## java ##
alternatives --install /usr/bin/java java /usr/java/latest/jre/bin/java 20000
## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/latest/jre/bin/javaws 20000

## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so
/usr/java/latest/jre/lib/i386/libnpjp2.so 20000

## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64
/usr/java/latest/jre/lib/amd64/libnpjp2.so 20000

## Install javac only if you installed JDK (Java Development Kit) package ##
alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 20000
alternatives --install /usr/bin/jar jar /usr/java/latest/bin/jar 20000

Use Java JDK absolute version (/usr/java/jdk1.7.0_02)

## java ##
alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_02/jre/bin/java 20000
## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0_02/jre/bin/javaws 20000

## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so
/usr/java/jdk1.7.0_02/jre/lib/i386/libnpjp2.so 20000

## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64
/usr/java/jdk1.7.0_02/jre/lib/amd64/libnpjp2.so 20000

## Install javac only if you installed JDK (Java Development Kit) package ##
alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_02/bin/javac 20000
alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0_02/bin/jar 20000

4b. Install Sun/Oracle JRE java, javaws and libjavaplugin.so
(for Firefox/Mozilla) with alternatives –install command

Use Java JRE latest version (/usr/java/latest)

## java ##
alternatives --install /usr/bin/java java /usr/java/latest/bin/java 20000

## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/latest/bin/javaws 20000

## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so
/usr/java/latest/lib/i386/libnpjp2.so 20000

## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64
/usr/java/latest/lib/amd64/libnpjp2.so 20000

Use Java JRE absolute version (/usr/java/jre1.7.0_02)

## java ##
alternatives --install /usr/bin/java java /usr/java/jre1.7.0_02/bin/java 20000

## javaws (32-bit only) ##
alternatives --install /usr/bin/javaws javaws /usr/java/jre1.7.0_02/bin/javaws 20000

## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so
/usr/java/jre1.7.0_02/lib/i386/libnpjp2.so 20000

## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64
/usr/java/jre1.7.0_02/lib/amd64/libnpjp2.so 20000

5. Check current java, javac, javaws and libjavaplugin.so versions

java -version
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)

javaws
Java(TM) Web Start 1.7.0_02
[...]

javac -version
javac 1.7.0_02

Note: Check libjavaplugin.so with restarting Mozilla Firefox and writing about:plugins on address bar.

6. Swap between OpenJDK and Sun/Oracle Java JDK/JRE 6 and 7 versions

java

alternatives --config java

There are 5 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/jre/bin/java
   2           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
 + 3           /usr/java/jdk1.6.0_26/jre/bin/java
   4           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
   5           /usr/java/jdk1.7.0_02/jre/bin/java

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

Note: java with [+] is currently on use

javaws

alternatives --config javaws

There are 3 programs which provide 'javaws'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/jre/bin/javaws
 + 2           /usr/java/jdk1.6.0_26/jre/bin/javaws
   3           /usr/java/jdk1.7.0_02/jre/bin/javaws

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

Note: java with [+] is currently on use

libjavaplugin.so (32-bit)

alternatives --config libjavaplugin.so

There are 3 programs which provide 'libjavaplugin.so'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/jre/lib/i386/libnpjp2.so
 + 2           /usr/java/jdk1.6.0_26/jre/lib/i386/libnpjp2.so
   3           /usr/java/jdk1.7.0_02/jre/lib/i386/libnpjp2.so

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

libjavaplugin.so.x86_64 (64-bit)

alternatives --config libjavaplugin.so.x86_64

There are 3 programs which provide 'libjavaplugin.so.x86_64'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/jre/lib/amd64/libnpjp2.so
 + 2           /usr/java/jdk1.6.0_26/jre/lib/amd64/libnpjp2.so
   3           /usr/java/jdk1.7.0_02/jre/lib/amd64/libnpjp2.so

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

javac

alternatives --config javac

There are 3 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.6.0_24/bin/javac
 + 2           /usr/java/jdk1.6.0_26/bin/javac
   3           /usr/java/jdk1.7.0_02/bin/javac

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

Note: java with [+] is currently on use

Post-Installation Setup

Add JAVA_HOME environment variable to /etc/profile file or $HOME/.bash_profile file

Java JDK and JRE latest version (/usr/java/latest)

## export JAVA_HOME JDK/JRE ##
export JAVA_HOME="/usr/java/latest"

Java JDK and JRE absolute version (/usr/java/jdk1.7.0_02)

## export JAVA_HOME JDK ##
export JAVA_HOME="/usr/java/jdk1.7.0_02"

## export JAVA_HOME JRE ##
export JAVA_HOME="/usr/java/jre1.7.0_02"