How to set the environment variables for Java in Windows (the classpath)?
Java does not need any environment variables to be set. However, setting some environment variables makes some things easier. PATH If the jre/bin folder is on the path, you don't have to qualify to run the java command. If the jdk/bin folder is on the path, you don't have to qualify to run the java and javac commands.
Like properties in the Java platform, environment variables are key/value pairs, where both the key and the value are strings. The conventions for setting and using environment variables vary between operating systems, and also between command line interpreters.
Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.
Verify JAVA_HOMEOpen a Command Prompt window (Win⊞ + R, type cmd, hit Enter). Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder. If it doesn't, your JAVA_HOME variable was not set correctly.
Set the following user environment variables (== environment variables of type user variables)
JAVA_HOME :
C:\Program Files\Java\jdk1.8.0_112
JDK_HOME :
%JAVA_HOME%
JRE_HOME :
%JAVA_HOME%\jre
CLASSPATH :
.;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
PATH :
your-unique-entries;%JAVA_HOME%\bin
(make sure that the longish your-unique-entries
does not contain any other references to another Java installation folder.Note for Windows users on 64-bit systems:
Progra~1 = 'Program Files' Progra~2 = 'Program Files(x86)'
Notice that these environment variables are derived from the "root" environment variable JAVA_HOME
. This makes it easy to update your environment variables when updating the JDK. Just point JAVA_HOME
to the fresh installation.
There is a blogpost explaining the rationale behind all these environment variables.
JAVA_TOOL_OPTIONS
with value -Dfile.encoding="UTF-8"
. This ensures that Java (and tools such as Maven) will run with a Charset.defaultCharset()
of UTF-8
(instead of the default Windows-1252
). This has saved a lot of headaches when wirking with my own code and that of others, which unfortunately often assume the (sane) default encoding UTF-8.Path
an entry C:\ProgramData\Oracle\Java\javapath;
. I anecdotally noticed that the links in that directory didn't get updated during an JDK installation update. So it's best to remove C:\ProgramData\Oracle\Java\javapath;
from the Path
system environment variable in order to have a consistent environment.In Windows inorder to set
Step 1 : Right Click on MyComputer and click on properties .
Step 2 : Click on Advanced tab
Step 3: Click on Environment Variables
Step 4: Create a new class path for JAVA_HOME
Step 5: Enter the Variable name as JAVA_HOME and the value to your jdk bin path ie c:\Programfiles\Java\jdk-1.6\bin and
NOTE Make sure u start with .;
in the Value so that it doesn't corrupt the other environment variables which is already set.
Step 6 : Follow the Above step and edit the Path in System Variables add the following ;c:\Programfiles\Java\jdk-1.6\bin
in the value column.
Step 7 :Your are done setting up your environment variables for your Java , In order to test it go to command prompt and type
java
who will get a list of help doc
In order make sure whether compiler is setup Type in cmd
javac
who will get a list related to javac
Hope this Helps !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With