What sets my Java Virtual Machine? I'm not understanding how my Java environment is getting set up.  If I have multiple versions of Java installed how does the correct version get selected when I start a Java dependent application?

I have both Apple's original 1.6 version of Java and Sun's more recent 1.8 installed.

If I type java -version I get

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)`


ls -l /usr/bin/java produces lrwxr-xr-x  1 root  wheel    74 Jun 16   2014 /usr/bin/java -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java where Current is pointed at Apple's 1.6 Java install.
In your current terminal session you can select the JVM using
/usr/libexec/java_home -v 1.8 see java_home --help for more options. 

For GUI applications you should set JAVA_HOME as an environment variable.  Setting Environment variables in Mac OS is explained in Environment variables in Mac OS X on StackOverflow. Be aware that ~/.launchd.conf is deprecated: man launchd.conon Yosemite


  ...launchd.conf is no longer respected by the system. ...