Installing Java Development Kit on Debian Linux
Java is a programming language and computing platform first released by Sun Microsystems in 1995.
Oracle Corporation acquired Sun Microsystems in 2010.

Debian Linux provides open source Java platform because of licensing issues.
This document explains how to install Java Development Kit (JDK) provided by Oracle.

Recent updates to Oracle JDK might have jeopardized stability of JDK on Linux. If you encounter issues after installing JDK from Oracle try installing OpenJDK instead:

apt-get install openjdk-7-jdk

This document assumes a clean install of JDK. If you installed other versions of Java on your computer apply your judgement when creating symlinks.

32 or 64 bit JDK?
To find out if you have 32 or 64 bit system open a terminal window.
On Gnome desktop you can open a terminal from Applications menu ( Applications/Accessories/Terminal ).
Press ENTER after each command.

uname -m
// i686 means you have 32 bit Linux
// x86_64 means you have 64 bit Linux

Download JDK binary from Oracle
Go to Oracle JDK download page

Click on Java Platform (JDK) 7u9 (first Java Download box).
Select Accept License Agreement radio button.

If your Linux is a 32 bit system click on jdk-7u9-linux-i586.tar.gz link next to Linux x86 .
If your Linux is a 64 bit system click on jdk-7u9-linux-x64.tar.gz link next to Linux x64 .
Save file to a local directory (e.g. Downloads ).

Extract contents
I prefer to install additional software in /opt directory. You can choose any other directory.
You need to login as root .
If you're using Gnome desktop open Root Terminal window ( Applications/Accessories/Root Terminal ).
Otherwise just open a terminal and login as root .

Press ENTER after each command.
(My system is a 64 bit Linux so I will use that version of JDK.)

cd /opt
mkdir jdk
cd jdk
cp ~/Downloads/jdk-7u9-linux-x64.tar.gz .
tar xvf jdk-7u9-linux-x64.tar.gz

That should create a directory called jdk1.7.0_09 .

rm jdk-7u9-linux-x64.tar.gz
ln -s jdk1.7.0_09 default

I like to provide a symlink (a.k.a. symbolic or soft link) called default linked to current software version.
Makes things easier when upgrading to newer version of Java . For example:

rm default
tar xvf jdk-7u10-linux-x64.tar.gz
ln -s jdk1.7.0_10 default

If directory structure is the same everything should work out of the box.

If you followed this document before you don't have to go through remaining steps, all the symlinks should work already.
If this is the first time you're installing Java JDK on your Linux system keep reading.

Add links to Java programs
As root user go to /etc/alternatives directory:

cd /etc/alternatives

Find all symlinks connected to old versions of Java programs:

ls -l |grep jvm

If nothing comes up try this:

ls -l |grep java

java symlink is used here as an example. Other symlinks could include: jar , javac , javah , jconsole , keytool , orbd , rmid , rmiregistry or serialver .
The complete list of executables and man page files is located at the end of this document.
If no files are listed just create new symlink.

The idea is to link all binary executables from the newly installed JDK to /etc/alternatives .
That directory exists for that purpose, to provide an alternative version of a program.

Remove old symlinks
For every listed symlink repeat the following steps (again java symlink is used as an example):

rm java

Create new symlink

ln -s /opt/jdk/default/bin/java

Command ln usually takes 2 parameters (source file name and target file name) but if target file name is the same as source file name you can skip the second parameter.

Link manual (man) pages
Man page files can be compressed, so look for both uncompressed and compressed files.
In this case man pages can be called java.1 or java.1.gz .

If old man page symlink exists remove it:

rm java.1

Create new man page symlink:

ln -s /opt/jdk/default/man/man1/java.1
// or
ln -s /opt/jdk/default/man/man1/java.1.gz

Open another root terminal and update files in man page directory:

cd /usr/share/man/man1
rm java.1.gz
// or
rm java.1

Create new symlink for man page :

ln -s /etc/alternatives/java.1
// or
ln -s /etc/alternatives/java.1.gz

Test symlinks
Run java program:

java -version

You should see messages similar to those:

java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

Test man page:

man java

You should see messages similar to those:

java - the Java application launcher

Repeat symlink creation for each program/man page listed below.
You don't have to link man pages if you don't need them.

Add more symlinks
Here is a list of files I usually link in /etc/alternatives when installing new JDK:

ln -s /opt/jdk/default/bin/jar /etc/alternatives/jar
ln -s /opt/jdk/default/man/man1/jar.1 /etc/alternatives/jar.1
ln -s /opt/jdk/default/bin/java /etc/alternatives/java
ln -s /opt/jdk/default/man/man1/java.1 /etc/alternatives/java.1
ln -s /opt/jdk/default/bin/javac /etc/alternatives/javac
ln -s /opt/jdk/default/man/man1/javac.1 /etc/alternatives/javac.1
ln -s /opt/jdk/default/bin/jconsole /etc/alternatives/jconsole
ln -s /opt/jdk/default/man/man1/jconsole.1 /etc/alternatives/jconsole.1
ln -s /opt/jdk/default/bin/keytool /etc/alternatives/keytool
ln -s /opt/jdk/default/man/man1/keytool.1 /etc/alternatives/keytool.1
ln -s /opt/jdk/default/bin/orbd /etc/alternatives/orbd
ln -s /opt/jdk/default/man/man1/orbd.1 /etc/alternatives/orbd.1
ln -s /opt/jdk/default/bin/rmid /etc/alternatives/rmid
ln -s /opt/jdk/default/man/man1/rmid.1 /etc/alternatives/rmid.1
ln -s /opt/jdk/default/bin/rmiregistry /etc/alternatives/rmiregistry
ln -s /opt/jdk/default/man/man1/rmiregistry.1 /etc/alternatives/rmiregistry.1
ln -s /opt/jdk/default/bin/serialver /etc/alternatives/serialver
ln -s /opt/jdk/default/man/man1/serialver.1 /etc/alternatives/serialver.1

Again man page files could be compressed, so for example man page for keytool could be keytool.1 or keytool.1.gz .
Remember to create symlinks in main man page directory ( /usr/share/man/man1 ) for each man page listed above.

As a bare minimum I would suggest creating symlinks for java , jar and keytool programs.

Set up JAVA_HOME environment variable
Login as root , go to /etc directory and edit profile file:

cd /etc
vi profile
// Add those two lines at the end:
export JAVA_HOME

You should see JAVA_HOME variable printed next time you log in and run:

set | grep JAVA
// or
export | grep JAVA

When using Gnome desktop closing and opening terminal window does not really log you out, so environment variables will not be refreshed.
Restart Linux to be sure.

Sample output from last command:

declare -x JAVA_HOME="/opt/jdk/default"