You're doing this at the command line, right? Here's what I did. I see the Java 5 executables at
/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/
You could make an alias by editing your .bash_profile (located in your home directory; if it's not there, just create it) to include the following:
Code:
alias java5="/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/java"
alias javac5="/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/javac"
After closing and reopening your open Terminal window (or typing "source ~/.bash_profile"), you could then type:
Code:
javac5 HelloWorld.java
java5 HelloWorld
If you don't like typing that extra "5" at the end, you can have the alias simply be "java" instead of "java5" - I just prefer not to override the default, but I don't think there's any harm in doing so. You can always go back to the way it was before by removing those lines from .bash_profile.
You could also skip my instructions and read over this very informative article:
http://forums.macosxhints.com/showthread.php?t=47531.
Hope this helps!