So, you just bought a new PC or Laptop with Windows 8 operating system, and wondering how to set PATH and Classpath on Windows 8; Or, you might have just upgraded your Windows 7 laptop to the professional edition of Windows 8 and looking to set JDK Path to compile Java programs. Not to worry, this is the second step for anyone who wants to learn Java programming. Of course, the first step is to install JDK. In this Java tutorial, we will see step by step guide to set Java PATH and CLASSPATH in the Windows 8 operating system. By the way, if you are learning Java in Windows 10 operating system, You should still be able to set the Java path and classpath in Windows 10 by following the steps given here, because navigation steps for modifying environment variables on Windows 10 and Windows 8 are almost same.
For absolutely Java beginners, It's important to know What is Path Environment variable is and Why do you need to set Path for Java? PATH is an environment variable, which contains the location of executable or commands. When you type a command in the command prompt, Operating System like Windows 7 or Windows 8, looks PATH to find and execute that command.
Actually, for running a Java program, you don't need to set PATH because Windows 8 comes with bundled JRE which is sufficient for running Java applications. Setting PATH simply means including the JDK bin directory into the PATH environment variable.
You need to set PATH to compile Java source code and create Java class files. JDK bin directory contains javac and java commands to compile and run Java programs. CLASSPATH is a little different than Path and it's used by JVM rather than Operating System to load classes at runtime.
I suggest reading the difference between Path and Classpath and How Classpath works in Java and to know more about these fundamental concepts.
And, If you are new to the Java world then I also recommend you go through The Complete Java MasterClass on Udemy to learn Java in a better and more structured way. This is one of the best and up-to-date courses to learn Java online.
Actually, for running a Java program, you don't need to set PATH because Windows 8 comes with bundled JRE which is sufficient for running Java applications. Setting PATH simply means including the JDK bin directory into the PATH environment variable.
You need to set PATH to compile Java source code and create Java class files. JDK bin directory contains javac and java commands to compile and run Java programs. CLASSPATH is a little different than Path and it's used by JVM rather than Operating System to load classes at runtime.
I suggest reading the difference between Path and Classpath and How Classpath works in Java and to know more about these fundamental concepts.
And, If you are new to the Java world then I also recommend you go through The Complete Java MasterClass on Udemy to learn Java in a better and more structured way. This is one of the best and up-to-date courses to learn Java online.
Setting JDK Path and Classpath in Windows 7, 8 and Windows 10
This tutorial assumes that you know how to download and install JDK on Windows 8 machine. By the way, if you are an absolute beginner and just starting with Java, then it's important to download the correct version of JDK based upon whether you are running a 32-bit or 64-bit version of Windows 8.
See how to install JDK 7 on Windows 8 operating system to learn more about installing JDK in Windows 7 and 8.
Once successfully installed, it's time to set PATH and Classpath for Java. By the way, If you know how to set PATH in Windows XP, then this would be very easy for you.
See how to install JDK 7 on Windows 8 operating system to learn more about installing JDK in Windows 7 and 8.
Once successfully installed, it's time to set PATH and Classpath for Java. By the way, If you know how to set PATH in Windows XP, then this would be very easy for you.
Steps to set JDK Path and Classpath in Windows 7 and Windows 8
Before setting JDK Path, let's first verify Type javac in command prompt in windows 8 and see the output, if you get javac is not recognized as an internal or external command, means JDK Path is not set.
- Confirm that PATH is not set for Java by typing javac in the command prompt.
- Open Control Panel and select System and Security
- Select System
- Select Advanced System Settings
- Select Environment Variables
- Select and Edit Path Environment variable
- Verify Java path by typing javac in command prompt
Step 1 : Open Control Panel in Windows 8
Step 2 : Select System
Step 3 : Select Advanced System Settings in Windows 8
Step 4 : Select Environment Variables
Step 5 : Select and Edit Path Environment variable in Windows 8
Step 6: Verify Java path by typing javac in command prompt
just type javac command, this time, you will see different output which shows various details of the java command rather than getting an earlier error. You can follow a similar process to set Classpath in Windows 8 as well.
But it’s not a good practice to use the CLASSPATH environment variable to run Java applications, instead, every Java application should use –classpath option to specify classpath. You can also see How Classpath works in Java for more details on Java Classpath.
Now you are ready to write Java code and compile and run them. Why not just try with the HelloWorld Java program. By the way, to know more about PATH and Classpath, which is essential for Java developers, See the following tutorials
Now you are ready to write Java code and compile and run them. Why not just try with the HelloWorld Java program. By the way, to know more about PATH and Classpath, which is essential for Java developers, See the following tutorials
Other Java fundamental Tutorials
- Difference between JAVA_HOME and java.home
- Difference between Path and Classpath in Java
- Difference between overloading and overriding in Java
- Top 10 Interview Questions on Abstract class and Interface
- 20 questions on Java design pattern and Software Design
- How to run Java program from the command line
- How to create and execute JAR file in Java
- How to remote debug Java program in Eclipse
- Top 10 Object-Oriented Design Principles
- Why Prefer Composition over Inheritance in Java
- 5 Books and Courses to learn Object-Oriented Programming
- 25 Software Design Interview Questions for Interviews
- 5 Best Books to learn Software Architecture
- My Favorite Courses to learn Software Architecture
36 comments :
i lost my predefined path for windows8.. instead of appending it i placed new java path and it does not work.. pls let me know if u kno how to make it work!! ash.jazz29@gmail.com
I did everything as it said, but I still get the error message when I type in javac. Any ideas what I did wrong?
@Anonymous, please provide some more details and I can try to help you. I know this PATH Setting can be tricky some time.
After working on the path as sa, I typed in java on the cmd window and it worked, but javac still doesn't.
This is my path value as at now:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\PharosSystems\Core\;C:\Program Files\Java\jre7\bin
hi, how can I get back my pre-defined path? I inadvertently deleted...:(
thx
I have the same person as the May 6 post. My PATH variable ends C:\Program Files (x86)\Java\jre7;C:\Program Files (x86)\Java\jdk\bin
I type "java" in the cmd prompt and it words: I type "javac" and I get the error message' "'javac' is not recognized...".
Any ideas? Thanks
Hi Anonymous, Can you double check if C:\Program Files (x86)\Java\jdk\bin directory contains "javac" command or not?
Does typing javac in the command prompt set the path automatically?
It gives me this error when i run a .bat file to run my java program: "D:\Videogames\Minecraft\server>java -Xmx1024M -jar
craftbukkit.jar -o true
'java' is not recognized as an internal or external command, operable program or batch file."
"D:\Videogames\Minecraft\server>PAUSE
Press any key to continue..."
How do I fix this?
I am also got problem with windows 8, I delete the whole path in environment variables could you please send the command prompt path to my email ( marin.fabregas@gmail.com ) thanks!!!
Nice Tutorial, for the new Os Windows 8. The Way you describing with the diagram is excellent. Thanks A lot. Representing the Windows 8 Setting Class path for the Java JDK in Diagrammatic Form. its Nice.
For more Detail Explanation for the Setting Class path for Java JDK in windows 8 Step by step
By mistaken I deleted my predefined path for windows8.. instead of appending it i placed new java path and it does not work..
Please give me a help to recover this problem
By the way, you can get to the point earlier.
Hello friends !
To set up path for java in windows 8, there are to box is one is user variable and second one is system variable, so from system variable(below box) find "Path" and select that and than click on "Edit" button. Type a Simi colon(;) at the end of the line and also do not delete line, and than past complete path of java installation folder for example :C:\Program Files\Java\jdk1.7.0_67\bin: and than click Ok.
Hope it will work for you
I am also got problem with windows 8, I delete the whole path in environment variables could you please send the command prompt path to my email ( gkalaivani94@gmail.com ) thanks!!!
I did the same thing and deleted the entire command path :( Could someone send it to shaun.mclaren@gmail.com
Thanks
some intelligent people have forgotten to mention to restart command prompt after updating the path variable. #hatersGonnaHate
@Anonymous, did you mean the author? Yes, whenever you change PATH or CLASSPATH or any other environment variable, you must close the existing cmd windows and open a new command prompt.
what do i put in the path?!
Thanks - yes I tried this repeatedly without luck, but afetr closing CMD prompt window and reopening it, javac command now works fine!
Just close the the command prompt and restart again. Then type javac, it will work.
@Puneet is right, whenever you change environment variable e.g. PATH, CLASSPATH, JAVA_HOME, JRE_HOME, TOMCAT_HOME, MAVEN_HOME etc, make sure you open a new command prompt, so that new set of environment variable takes effect and available in shell.
Hello friends,
While adding path I deleted path which is related to system as well as other installed apps.so if I type any commands in cmd promt like( ipconfig etc) am getting error...lt can work only for java related comands.so someone please suggest me about how to regain the path.am really tired of googling it still I couldn't find.
Hello friends,
While adding path I deleted path which is related to system as well as other installed apps.so if I type any commands in cmd promt like( ipconfig etc) am getting error...lt can work only for java related comands.so someone please suggest me about how to regain the path.am really tired of googling it still I couldn't find.
i lost my predefined path for windows8.. instead of appending it i placed new java path and it does not work.. pls let me know if u kno how to make it work send me how to set my perdefined path for windows 8 64 bit..my mail id is divya34.k@gmail.com
Hi Divya,
For windows 8, there is an alternate approach to set the java path using "C:\ProgramData\Oracle\Java\javapath" . This discussion in stack-overflow might be helpful..
http://stackoverflow.com/a/34375859/5699213
Instead of adding it,I deleted the entire path in windows7.Can any one tell how to set entire path?
i lost my predefined path for windows 8.. instead of appending it i placed new java path and it does not work.. please let me know if u know how to make it work send me how to set my predefined path for windows 8 64 bit..my mail id is sandhya.battagani@gmail.com
Read more:
C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Git\cmd;
This is a predefined code for win 8.
If you want your javac to work, you need to make new path. Simply go to Environment Variables and press new.
Variable name should be: JAVA_HOME
And path should be something like this C:\Program Files\Java\jdk1.8.0_111\bin;
Then, you go to path and at the end of the path code add this %JAVA_HOME%\bin;
But, at the start of your path code u need to add java path(Same as JAVA_HOME)
End code for Path should be like this:
C:\Program Files\Java\jdk1.8.0_111\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Git\cmd;%JAVA_HOME%\bin;
Hope this helps.
I set the path as you dictated bu guess what?
compilation process works but while running,it throws error message:Could not find or load main class file.-_- i'm pissed off.
I set path and classpath properly but still it show ''MAIN CLASS NOT FOUND ERROR''during execution.
I set the path I am using Windows 10 I created java home and past the path. When I am writing java it's working but when I am writing javac it's saying javac is an internal external command why???
Hello @Anonymous, looks like you have included JRE in your path and not JDK. The JRE only contains java.exe hence it is working but it doesn't contain javac.exe hence javac is showing not an internal or external command. If you can paste the path of your JAVA_HOME, I can say for sure if its JRE or JDK. Alternatively you just go to the bin folder of JAVA_HOME and see if javac.exe exists or not.
Helo @Anonymous, to solve the "MAIN CLASS NOT FOUND ERROR" please see the article, there are host of reason when this error comes and I have described them in detail there.
I have bychance deleted the whole path and added c:/program files/java14.0.1/bin
You didn't even mention the CLASSPATH setup so take it out of your title!
Post a Comment