I have unpacked my jdk in /usr/java/.
and I put CLASSPATH, PATH, JAVA_HOME into /etc/profile like below.
export JAVA_HOME=/usr/java/jdk1.7.0_21 expor
Providing javac is set up through /etc/alternatives/javac, you can add to your .bash_profile:
javac
/etc/alternatives/javac
JAVA_HOME=$(l=$(which javac) ; while : ; do nl=$(readlink ${l}) ; [ "$nl" ] || break ; l=$nl ; done ; echo $(cd $(dirname $l)/.. ; pwd) ) export JAVA_HOME