Install Sun / Oracle Java JDK under Ubuntu

wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/installit/master/install.java-jdk.sh -O - | bash -

#!/bin/bash

# ensure that this script is run by root
if [ $(id -u) -ne 0 ]; then
  sudo $0
  exit
fi

# install debconf
apt-get install -y debconf-utils

# create answer file
debconf-set-selections <<\EOF
oracle-java8-installer shared/accepted-oracle-license-v1-1 select true
EOF

# ensure that add-apt-repository is installed
. /etc/os-release
if [ "${ID}" == "debian" ] && [ "${VERSION_ID}" == "7" ] ; then
  # Debian Wheezy
  apt-get install -y python-software-properties
else
  # Ubuntu and Debian Jessie
  apt-get install -y software-properties-common
fi

# add repository
add-apt-repository -y ppa:webupd8team/java

# fix distribution name on Debian
for FILE in $(find /etc/apt/sources.list.d/ -name "*webupd8team*.list"); do
  sed -i 's|wheezy|precise|g;s|jessie|trusty|g' ${FILE}
done

# update repository
apt-get update -qq

#  bypass the apt-cacher-ng proxy
echo 'Acquire::HTTP::Proxy::download.oracle.com "DIRECT";' > /etc/apt/apt.conf.d/99_oracle

# install
apt-get install -y oracle-java8-installer

# set Java environment variables
apt-get install -y oracle-java8-set-default

# set java 8 as default java version
update-java-alternatives -s java-8-oracle

# move java desktop symbols
[ -f /usr/share/applications/JB-mission-control-jdk8.desktop ] && sed -i 's|Categories=Development;Java;|Categories=Application;Network;|g' /usr/share/applications/JB-mission-control-jdk8.desktop

Install JDK under Debian 7 (minimal)
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" > /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
echo 'Acquire::HTTP::Proxy::download.oracle.com "DIRECT";' > /etc/apt/apt.conf.d/99_oracle
apt-get update
echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
apt-get install -y oracle-java7-installer
apt-get install -y oracle-java7-set-default

Download JDK manually
# v7
URL=http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.tar.gz
# v8
URL=http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz
# download
wget --continue --no-check-certificate --header "Cookie: oraclelicense=a" ${URL} -O /tmp/${URL##*/}

# http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz?AuthParam=1458983739_a16ec49d4ccc02fd689b10ad958ab0ce

# fix repo key
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886

OPTIONAL: Uninstall OpenJDK
sudo apt-get remove -y openjdk-7-jre-headless

Display your current java version
java -version

# configure systemwide profile
echo "export JAVA_HOME=/opt/jvm/current" > /etc/profile.d/java.sh

Links
http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html
http://www.webupd8.org/2012/11/oracle-sun-java-6-installer-available.html - HowTo, install Java under Ubuntu and Debian
https://launchpad.net/~webupd8team/+archive/java - webupd8team Java repository
https://www.thomas-krenn.com/de/wiki/Oracle_Java_JRE_unter_Ubuntu_installieren