The most important environment variable for Java is the class path. Class path is a special concept which allows Java to locate different libraries. If a application needs access to some database drivers then you would have to put it in the class path.
When you download a library (like Log4j) then you need to put the JAR file onto the class path. If you installed Log4j in C:\log4j\log4j.jar then you can add it to the class path by -
windows - SET CLASSPATH=%CLASSPATH%;c:\log4j\log4j.jar
linux - export CLASSPATH=$CLASSPATH;/home/user/log4j/log4j.jar
You can also change the class path directly using the java and javac command as arguments. This allows you to have different class path's for different applications.