Default JAVA, $JAVA_HOME vs sudo update-alternatives --config java
<p>I am on Ubuntu and I have set the following in my <code>~/.bashrc</code> file:</p>

<pre><code>export JAVA_HOME=/opt/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
</code></pre>

<p>and then:</p>

<pre><code>echo $JAVA_HOME
&gt;/opt/jdk1.8.0_91

java -version
&gt;java version "1.8.0_91"
&gt;Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
&gt;Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
</code></pre>

<p>at the first glance, the command <code>sudo update-alternatives --config java</code> was not showing my manually installed Java, so I installed it to the command with <code>sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_91 1</code>.</p>

<p>Now, the command <code>sudo update-alternatives --config java</code> drops down the list of all Java versions being installed like that:</p>

<pre><code>0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
1            /opt/jdk1.7.0_51/bin/java                        1         manual mode
* 2            /opt/jdk1.8.0_91                                 1         manual mode
3            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
4            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
</code></pre>

<p>But switching between these using the prompt of the <code>sudo update-alternatives --config java</code> does not affect <code>$JAVA_HOME</code> and then <code>$java -version</code>.</p>

<p>My question is, what does <code>sudo update-alternatives --config java</code> exactly do after switching to another alternative with respect to the settings in the <code>$JAVA_HOME$</code> variable?  </p>