Depends what OS your running and what you mean by "environment variables"
I will assume you are running windows, and want to set the PATH and CLASSPATH so that you can write java, javac, javadoc, javap etc in the command line.
Go to system properties (control panel), then advanced system settings and there should be a button that says environment variables.
You then need to either edit/or create a new variable called PATH and add the java bin directory to this (usually C:\JDK1.5\bin), if there is already a PATH variable you can add to it by separating with a semi-colon. This basically tells the OS where to look when you type javac etc.
The CLASSPATH variable can be set in the same way BUT it is used to store packages and classes. I am not entirely sure but I think javac searches the current directory and the CLASSPATH when you import a package, so you can just put them in the directory you are working in.
If you have done this correctly type java -version in cmd prompt and you should see a printout telling you the current version of the jvm.
If you want to retrieve Environment variables in a program then search the java documentation on the SUN website as there are system methods to achieve this
e.g. System.getProperty("os.name")
Hopefully this has helped