Firstly, This installation is for 64-bit, windows 10 OS.
For others also it is basically the same. But be sure with OS in your system[32 bit or 64 bit] while downloading JDK and JRE(These comes in Java file).
1) Now download the java installer from the web. Better from the site. Make sure the installer is supported in the os.
2) Install the java package but be aware of the location where you are installing it. Generally it is in C://Program Files/Java...
3) After installation is done, open the java folder and in which you will find 2 folders JDK and JRE.
4) now minimize the folder and open Control panel.
5) In "control panel" go to "System and Security" in which you will find "System" .
6) Inside the "System" you need to click on the "Advanced System Settings" which are generally on the left panel.
7) After you click on the panel you will see a window, Search for the "Environment Variable" button, in which you will find 2 sections a) user variable and b) system variable
8) Path Setting :-
a) In "User Variable" table, Double click on the "path" and there you will see a window with 2 input options.Now open the java folder which you have minimized and open "bin" file in "Jdk" folder, now copy the the location address from the on the top panel just below view button.And paste it in the "Variable value" input text region and click ok.
b) In "System Variables" table, Double click on the "CLASSPATH" row and you will see another window poping up named as "Edit Environment Variable".Now open the java folder which you have minimized and open "lib" file in the "jre" folder and copy the "location address".Now click on the "New" button in "Edit Environment Variable" and paste the location address copied from "lib" in "jre" folder into the new row and click on "ok".
9) Click on "ok" in the "Environmental Variables" and close "control panel".
10) Now try to compile and run the ".java" program that you wrote from "command prompt" to check whether its working or not.
here is the screenshots :-