If you don't have admin rights, use the below command to set environment variables for java using the command prompt
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";
Modify the environment variable.
setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx -m PATH "%PATH%;%JAVA_HOME%\bin";
Answer from Sathiamoorthy on Stack OverflowVideos
If you don't have admin rights, use the below command to set environment variables for java using the command prompt
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";
Modify the environment variable.
setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx -m PATH "%PATH%;%JAVA_HOME%\bin";
Set the JAVA_HOME Variable
Windows 7 – Right click My Computer and select Properties > Advanced
Windows 8 – Go to Control Panel > System > Advanced System Settings
Windows 10 – Search for Environment Variables then select Edit the system environment variables

Click the Environment Variables button.
Under System Variables, click New.
In the Variable Name field, enter either:
JAVA_HOME if you installed the JDK (Java Development Kit)
or
JRE_HOME if you installed the JRE (Java Runtime Environment). In the Variable Value field, enter your JDK or JRE installation path .

Open Command Prompt as Administrator.
Set the value of the Environment variable to your JDK (or JRE) installation path as follows:
setx -m JAVA_HOME "C:\path_to_Java\jdk_version"
Java SE Development Kit 8u112 on a 64-bit Windows 7 or Windows 8
Set the following user environment variables (== environment variables of type user variables)
JAVA_HOME :C:\Program Files\Java\jdk1.8.0_112JDK_HOME :%JAVA_HOME%JRE_HOME :%JAVA_HOME%\jreCLASSPATH :.;%JAVA_HOME%\lib;%JAVA_HOME%\jre\libPATH :your-unique-entries;%JAVA_HOME%\bin(make sure that the longishyour-unique-entriesdoes 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.
Optional recommendations
- Add a user environment variable
JAVA_TOOL_OPTIONSwith value-Dfile.encoding="UTF-8". This ensures that Java (and tools such as Maven) will run with aCharset.defaultCharset()ofUTF-8(instead of the defaultWindows-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. - When JDK is installed, it adds to the system environment variable
Pathan entryC:\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 removeC:\ProgramData\Oracle\Java\javapath;from thePathsystem 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 !
This can be caused by multiple different reasons.
Try 'where java' and 'where javac' to see where they point to. You should thenbe able to find the exact path from where java and javac are being called in your environment.
Also ensure that you only have one jdk/jre in your Path. You can try to move %JAVA_HOME% to be the first element in the Path list.
Move %JAVA_HOME%\bin to the top and then check java -version in a new cmd window. Make sure you do it in both, User variables as well System variables. Check this to learn more about a similar problem and its solution.
The registry entries for the variables should be REG_EXPAND_SZ and not REG_SZ.
System: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
User: HKEY_CURRENT_USER\Environment
You may have to delete and recreate the variable. If it's a system variable, a reboot will probably be needed to pick up the change.
call echo %CLASSPATH% will expand the inner variables
similarly: call set "Expanded=%CLASSPATH%"
