Nice little script for OSX
Simply source this file while initializing your environment. This will give you two commands:
setjdk - set the jdk for just a terminal
defaultjdk - set the jdk for the system (all future terminals and java applications). Will prompt you for a password.
Each has tab completion, such as:
Run as follows:
Add this directly to your .bash_profile or put it in another file and source it from there.