• Post Reply Bookmark Topic Watch Topic
  • New Topic

writing your first java program  RSS feed

 
dang khoa
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im having trouble compiling and executing the program. When I enter the directory \Program Files\Java\src I get "The system path cannot be identified". Should I save the code in a different directory?
ps Im using windows 7
 
Yosuf Ibrahim
Ranch Hand
Posts: 128
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try typing full path, for example, "C:\Program Files\Java\src".

But I am also finding it difficult to understand why are you typing the path, as far as I know you should just be pressing F5 for example to compile, what IDE are you using??
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Windows note: If your path contains a space character anywhere, then the whole path must be enclosed in double quotes. This especially goes for "Program Files" but also file names as well.

P.S. This may not have anything to do with your current problem but is worth noting.
 
Pete Letkeman
Ranch Foreman
Posts: 914
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:A Windows note: If your path contains a space character anywhere, then the whole path must be enclosed in double quotes. This especially goes for "Program Files" but also file names as well.

This is not the always the case for all Windows systems. For instance on my Windows 10 Pro 64 bit system I have no quotes in the path and it works fine for me.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Letkeman wrote:
Carey Brown wrote:A Windows note: If your path contains a space character anywhere, then the whole path must be enclosed in double quotes. This especially goes for "Program Files" but also file names as well.

This is not the always the case for all Windows systems. For instance on my Windows 10 Pro 64 bit system I have no quotes in the path and it works fine for me.

That is the version that I am also using and I'm using cmd.exe as my command line program. It requires the quotes.
This works:
This doesn't:
 
Pete Letkeman
Ranch Foreman
Posts: 914
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to get too far off topic:

Yes cmd.exe does appear to require quotes when spaces are in the path of the command that you want to execute as you have just stated and demostrated.
However, it would appear as though the path variable does not need to have quotes for things to work. Perhaps Windows puts them in automatically for you if you don't provide them or maybe there is an hidden option somewhere for this.
When I installed Microsoft Visual Studio Code I got this added to my path C:\Program Files (x86)\Microsoft VS Code\bin just like that without any quotes at all. And I do not have any quotes in my path either and everything works fine for me.
This is why I say that some times you do not need quotes when dealing with the Windows Environment variable named path.

I think it's time to see that I can find out from Microsoft via Google, however I suspect that anything found will contradict itself later on as Microsoft does this sometimes.
 
Pete Letkeman
Ranch Foreman
Posts: 914
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can believe Microsoft:
https://blogs.msdn.microsoft.com/oldnewthing/20060929-06/?p=29533 wrote:The purpose of quotation marks is to allow a character that would normally be interpreted as a delimiter to be included as part of a file name. Most of the time, this delimiter is the space. The CreateProcess function uses a space to separate the program name from its arguments. Most programs separate their command line arguments with a space. But the PATH environment variable doesn't use spaces to separate directories. It uses semicolons.

This means that if you want to add a directory with spaces in its name to the path, you don't need quotation marks since spaces mean nothing to the PATH environment variable. The quotation marks don't hurt, mind you, but they don't help either.

On the other hand, if the directory you want to add contains a semicolon in its name, then you do need the quotation marks, because it's the semicolon that you need to protect.

This is dated September 29, 2006.
You can read this and comments regarding this here
https://blogs.msdn.microsoft.com/oldnewthing/20060929-06/?p=29533
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any indication in the original post that he was talking about the PATH environment variable.
 
Pete Letkeman
Ranch Foreman
Posts: 914
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:I don't see any indication in the original post that he was talking about the PATH environment variable.

Correct. I was initially replied to:
Carey Brown wrote:A Windows note: If your path contains a space character anywhere, then the whole path must be enclosed in double quotes. This especially goes for "Program Files" but also file names as well.

Which is where I or maybe we got a little of topic.

Edit: Grammar fixed
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dang khoa wrote:Im having trouble compiling and executing the program. When I enter the directory \Program Files\Java\src I get "The system path cannot be identified". Should I save the code in a different directory?
ps Im using windows 7

Getting back to your original question. No, you should never put your java programs anywhere inside "C:\Program Files". Make your own directory. Something like "C:\java projects". Then your Java source would go into "C:\java projects\MyProjectName\src".
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the CodeRanch, dang khoa!

What exactly are you typing at the command line?  Could you copy and paste that in your next post, along with the full text of the error message?
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dang khoa wrote:When I enter the directory \Program Files\Java\src I get "The system path cannot be identified". Should I save the code in a different directory?

Well, regardless of what that error message is all about... Yes, you should save the code in a different directory. You should not store data under the \Program Files\ folder in a Windows computer, because that's where the installer puts programs. Your Windows installation doesn't seem to care, but many installations set permissions on that folder so that general users can't use its subfolders. You may find that if you upgrade to Windows 10 that it sets those permissions too. So yes, put your code elsewhere.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!