String path = "C:\\Documents and Settings\\Manoj\\Desktop";
path = path.replace("\\", "/");
// or
path = path.replaceAll("\\\\", "/");

Find more details in the Docs

Answer from Fred on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › paths.html
PATH and CLASSPATH (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
You should have only one bin directory for the JDK in the path at a time (those following the first are ignored), so if one is already present, you can update that particular entry. The following is an example of a PATH environment variable: C:\Java\jdk1.7.0\bin;C:\Windows\System32\;C:\Win...
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-set-java-path-in-windows-and-linux
How to Set Java Path in Windows and Linux? - GeeksforGeeks
July 23, 2025 - Step 1: Open a Command Prompt window. ... Step 2: You should see the path to your Java installation printed in the Command Prompt.
Discussions

path - Setting up enviroment variables in Windows 10 to use java and javac - Stack Overflow
I got a new laptop with Windows 10 and I want to set it up so I can use java and javac from the command line. I have searched online but all the guides are for previous versions, and I don't want to mess around with something I don't understand. ... Save this answer. ... Show activity on this post. Just set the path ... More on stackoverflow.com
🌐 stackoverflow.com
java adding to path
Adding something to the path just makes the commands in the folder available everywhere system wide. The way an OS (not limited to Windows) works is that it searches certain folders for the commands you enter in the terminal (console). If it doesn't find the command, it tells you that the command you entered is not recognized. By adding a folder to the path you tell the OS to also search that particular folder when you enter a command. For Java, you need javac and java from the console. The former compiles your source code, the latter executes it. Had you not added the folder to the path, you would always need to type C:\Program Files\Java\jdk-17\bin\javac when you want to compile a program. By adding the folder to the path javac becomes sufficient. More on reddit.com
🌐 r/javahelp
3
1
August 5, 2023
Java path, Windows 10

Specifying the JDK in the eclipse.ini file wasn't working?

More on reddit.com
🌐 r/learnjava
12
13
April 3, 2019
Need help opening .JAR files
My file association is: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.jar] @="jarfile" [HKEY_CLASSES_ROOT\jarfile\shell\open\command] @="\"C:\\Program Files\\Java\\jre1.8.0_144\\bin\\javaw.exe\" -jar \"%1\" %*" Try specifying javaw.exe (the hidden console version of 'java.exe') as the 'open with', then you may have to edit it to add the "-jar". Sometimes I just make a .bat file to run the jar if I don't want to mess the the machine's associations. More on reddit.com
🌐 r/windows
4
1
August 23, 2018
🌐
Medium
azimuahamed.medium.com › java-environment-variables-setup-windows-11-58fe71e43b5e
JAVA Environment Variables Setup Windows 11 | by Azim Uddin Ahamed | Medium
August 1, 2024 - For example, if you installed JDK 11, you might find a folder like jdk-11.x.x. ... In the System window, click on “Advanced system settings” on the left sidebar. In the System Properties window, click the “Environment Variables” button.
🌐
C# Corner
c-sharpcorner.com › article › how-to-set-up-the-java-path-on-windows
How to Set Up the Java Path on Windows
December 27, 2024 - Paste the path to the JDK’s bin directory (e.g., C:\Program Files\Java\jdk-21\bin). Click OK to save the changes. Create JAVA_HOME Variable (Optional but Recommended). In the same Environment Variables window, click New under System variables.
🌐
javaspring
javaspring.net › blog › java-path-in-windows
Java Path in Windows: A Comprehensive Guide — javaspring.net
... In the “System variables” section, find the “Path” variable and click “Edit”. Click “New” and add the path to the bin directory of your JDK installation, for example, C:\Program Files\Java\jdk-<version>\bin.
Find elsewhere
🌐
Oracle
java.com › en › download › help › path.html
How do I set or change the PATH system variable?
% /usr/libexec/java_home -v 1.8.0_73 --exec javac -version · To find out if the path is properly set: In a terminal windows, enter: % java -version This will print the version of the java tool, if it can find it.
🌐
XDA Developers
xda-developers.com › home › windows11 › how to set the java path in windows 11
How to set the Java path in Windows 11
November 29, 2023 - In the new window that appears, click on the New button under System variables. Type in JAVA_HOME in the Variable name box. For Variable value, type in the path to your JDK folder — in this example, the path is “C:\Program Files\Java\jdk-21
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › io › pathOps.html
Path Operations (The Java™ Tutorials > Essential Java Classes > Basic I/O)
// Microsoft Windows syntax Path path = Paths.get("C:\\home\\joe\\foo"); // Solaris syntax Path path = Paths.get("/home/joe/foo"); System.out.format("toString: %s%n", path.toString()); System.out.format("getFileName: %s%n", path.getFileName()); System.out.format("getName(0): %s%n", ...
🌐
Reddit
reddit.com › r/javahelp › java adding to path
r/javahelp on Reddit: java adding to path
August 5, 2023 -

what does adding java to path does on windows? I started a local java short course sometime ago but I had to differ it. I started watching some online tutorials but none of them added java "to path" (system properties ->Environment Variables -> click on path -> click edit -> click new paste (C:\Program Files\Java\jdk-17\bin) which I did in the local course I joined.

Top answer
1 of 3
10
Adding something to the path just makes the commands in the folder available everywhere system wide. The way an OS (not limited to Windows) works is that it searches certain folders for the commands you enter in the terminal (console). If it doesn't find the command, it tells you that the command you entered is not recognized. By adding a folder to the path you tell the OS to also search that particular folder when you enter a command. For Java, you need javac and java from the console. The former compiles your source code, the latter executes it. Had you not added the folder to the path, you would always need to type C:\Program Files\Java\jdk-17\bin\javac when you want to compile a program. By adding the folder to the path javac becomes sufficient.
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Blogger
javarevisited.blogspot.com › 2013 › 02 › windows-8-set-path-and-classpath-java-windows-7.html
How to set Java Path and Classpath in Windows 7, 8 and Windows 10 - Tutorial
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.
🌐
Java2Blog
java2blog.com › home › core java › java path › how to set java path in windows 10
How to set java path in windows 10 - Java2Blog
January 11, 2021 - In System variable window, locate Path and click on Edit.... Double click on the empty row and add %JAVA_HOME%\bin.
🌐
Super User
superuser.com › questions › 1385923 › javac-path-setup-windows-10
java - javac path setup windows 10 - Super User
December 19, 2018 - For javac, you will likely want to highlight your Path variable (under System variables), then Edit it and add an entry like C:\Program Files\Java\jdk_x.x.x\bin to the list (since the bin folder is where javac.exe typically resides).
🌐
Medium
programming-tech.medium.com › how-to-path-set-java-in-windows-10-download-and-install-java-3af92d60e631
How to Path set java in windows 10? Download and Install java | by Programming tech | Medium
May 13, 2021 - In this tutorial I will show you how to set JAVA Path in PATH variable as environment variable in Windows 10 operating system.
🌐
Coderanch
coderanch.com › t › 697661 › java › set-windows
set-up on windows 10 (Beginning Java forum at Coderanch)
When executing echo %path% from ...\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;C:\Program Files\dotnet\;C:\Program Files\Java\jdk-9\bin\;C:\Program Files\Microsoft VS Code Insiders\bin;C:\Program Files\Microsoft ...
🌐
javaspring
javaspring.net › blog › set-java-path-in-windows-11
Setting Java Path in Windows 11: A Comprehensive Guide — javaspring.net
Add the Java Path In the Edit environment variable window, click New and paste the path to the Java bin directory (e.g., C:\Program Files\Java\jdk-17.0.1\bin). Click OK to save the changes.
🌐
Specinnovations
help.specinnovations.com › configuring-java-home-on-windows
Configuring JAVA_HOME Environment Variable on Windows
Paste the copied JDK path (e.g., C:\Program Files\Java\jdk-17) into the Variable value field. ... Click OK to close the Edit or New System Variable dialog. Click OK again to close the Environment Variables dialog, and then OK to close the System Properties window. Example: For a JDK installed at C:\Program Files\Java\jdk-21...
🌐
GitHub
github.com › openjdk › jdk › blob › master › src › java.base › windows › classes › sun › nio › fs › WindowsPath.java
jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java at master · openjdk/jdk
import java.lang.ref.WeakReference; · import static sun.nio.fs.WindowsNativeDispatcher.*; import static sun.nio.fs.WindowsConstants.*; · /** * Windows implementation of Path · */ · class WindowsPath implements Path { · // The maximum path that does not require long path prefix.
Author   openjdk
🌐
Oracle
docs.oracle.com › cd › E19062-01 › sun.mgmt.ctr36 › 819-5418 › 6n7gk6imj › index.html
Java Environment Variables and Path (Sun Management Center 3.6.1 Installation and Configuration Guide)
The Edit System Variable window ... %SystemRoot%\system32;%SystemRoot%, the new path statement would then be %SystemRoot%\system32;%SystemRoot%;c:\j2version-number\bin where version-number is the JDK version....