Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

correct slash

 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read that in windows backslash is used to make classpath while in unix forward slash but for my windowxp both are working.

C:\WINDOWS\system32>java -cp F:\Music\Audio Hello
hello

C:\WINDOWS\system32>java -cp F:/Music/Audio Hello
hello
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on which character(s) an operating system recognizes as a file separator.
See this wikipedia article.
 
Ivan Jozsef Balazs
Rancher
Posts: 981
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle Klap wrote:It depends on which character(s) an operating system recognizes as a file separator.


It also might depend on the various programs.

This does not work for me on Windows from the command shell, because dir seems to take / for the beginning on option:
dir build/WEB-INF

This however does:
dir build\WEB-INF

 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's why the wikipedia article I linked to specifies the OS and Shell contexts.
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan Jozsef Balazs wrote:
Jelle Klap wrote:It depends on which character(s) an operating system recognizes as a file separator.


It also might depend on the various programs.

This does not work for me on Windows from the command shell, because dir seems to take / for the beginning on option:
dir build/WEB-INF

This however does:
dir build\WEB-INF



It works for classpath not for dir command.
 
Angus Comber
Ranch Hand
Posts: 90
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ankita modi. wrote:It works for classpath not for dir command.


In addition, Unix based operating systems use / for file separators, while Windows uses \.

Unix based uses : for token separator while Windows uses ;.

It looks like javac in your case can work with / or \

You can also install Cygwin (http://www.cygwin.com) on a Windows machine which provides a Unix style environment.
 
Winston Gutkowski
Bartender
Pie
Posts: 10492
64
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ankita modi. wrote:I read that in windows backslash is used to make classpath while in unix forward slash but for my windowxp both are working.

I suspect that it may have to do with the fact that the 'java' command uses Java conventions; and in Java '/' is recognised as a file (or, more correctly, a directory or path) separator in the right context. For example, the java.io.File class accepts '/' as a path separator regardless of what system the program is running on.

My question is: when will Microsoft get around to accepting what pretty much the rest of the computer world already uses?
Answer: probably never; and I'm certainly not going to hold my breath waiting.

Winston

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic