It depends where you develop your program. If you use and kind of IDE Java can usually be changed in the project settings.
If you compile your program via command line (meaning
javac etc.) you can change the desired Java environment by adding the following llines to your
~/.bashr_profile (which is run every time you open a terminal. You didn't tell which shell you use so I assume it is bash. You also did not state which distribution you run. Arch Linux for example offers a nice and easy script to change the Java environment,
archlinux-java. The general case:
Add the following lines to the
Save, quit, logout and login again and you should be good to go.