Download and install Java 1.6 from http://support.apple.com/kb/dl1572 and install.
Set Java 1.6 as your default using
/usr/libexec/java_home -v 1.6
I need to use NetBeans 7.3.1 (newer versions require Java 1.7) which is downloaded from https://netbeans.org/downloads/7.3.1.
To ensure that NetBeans runs using Java 1.6 edit the configuration file
/Applications/NetBeans/NetBeans 7.3.1.app/Contents/Resources/NetBeans/etc/netbeans.conf
-- which is actually a bash script! -- and define the netbeans_jdkhome environment variable
netbeans_jdkhome=$(/usr/libexec/java_home -v 1.6)
And that is it. You now have Java 6 and Java 7 on your Mac. If you want Java 1.6 to be the default for you always then add the following to your rc script
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)