slash vs backslash

R

Razvan

Hi!




In order to compile an application I can do: (I am on Windows)

javac name\mihaiu\test\CTest.java
javac name/mihaiu/test/CTest.java


but when I run it I must do:

java name/mihaiu/test/CTest

because the backslash version FAILS:

java name\mihaiu\test\CTest

The backslashes won't work even if I am on a windows platform
! Why is this happening ? On windows the backslash is the separator.





Regards,
Razvan
 
F

Flip

In order to compile an application I can do: (I am on Windows)
javac name\mihaiu\test\CTest.java
javac name/mihaiu/test/CTest.java
I believe this works cause Windows is trying to be nice and helpful. I
think it's replacing the "/" with "\" cause Windows uses the backslashes
natively. I'm not 100% sure, but I think Linux wouldn't be as friendly.
OH, don't get me wrong, friendly doesn't necessarily equal
better/good/preferred. By no means! As you can see this flexibility
results in ambiguity and confusion which is never good. So, for linux's
complexity, it's unambiguous and exact, resulting in no problems (hopefully!
:>).
but when I run it I must do:
java name/mihaiu/test/CTest
Yup, cause now, you're running the java.exe program passing in the
name/mihaiu/test/CTest as an application parameter/argument. Therefore
Windows runs the java.exe program, and passes your argument to the program,
where the java.exe will interpret the slashes. Java won't be as nice for
you as Windows was. It helps to think of where you are running things.
Windows runs the java.exe program, then once java.exe is up and running,
it's passed the arguments you typed out, and then it's in control of them,
which is why the right slashes are required, no ambiguity. I get caught on
this all the time too. :<
The backslashes won't work even if I am on a windows platform
! Why is this happening ? On windows the backslash is the separator.
Yup the backslash is the path separator, but it's Windows trying to help you
out. For example, try swapping the slashes in your URLs in IE, both will
work. That's Billy Boy trying to help you out. I'm not sure what Netscape
does. Java is meant to be more straight forward, is a programming language
not an OS and therefore needs to be more exactly. Also, Java was developed
by a unix company (SUN, well, ok, a Solaris UNIX company, but it's not MS
:>) and therefore you'll find a lot of UNIX oriented "things" that are
ported over to Windows to make them cross platform.

But then again, I'm only on my first cup of coffee this am and I could be
all wrong. :>

Good luck! :>
 
J

Joona I Palaste

Flip said:
Yup the backslash is the path separator, but it's Windows trying to help you
out. For example, try swapping the slashes in your URLs in IE, both will
work. That's Billy Boy trying to help you out. I'm not sure what Netscape
does. Java is meant to be more straight forward, is a programming language
not an OS and therefore needs to be more exactly. Also, Java was developed
by a unix company (SUN, well, ok, a Solaris UNIX company, but it's not MS
:>) and therefore you'll find a lot of UNIX oriented "things" that are
ported over to Windows to make them cross platform.

If IE is so "helpful", then it also goes against the HTTP specification.
You can test it by giving a file on a UNIX web server a name containing
a backslash. Then try to request that file from IE. For example, suppose
the name is "foo\bar" on the server "http://mycorp.com". Now try to
request "http://mycorp.com/foo\bar". See if you can get the correct
file.
This could be a fancy way to prevent IE users from viewing content on
UNIX webservers... =)

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'It can be easily shown that' means 'I saw a proof of this once (which I didn't
understand) which I can no longer remember'."
- A maths teacher
 
L

Lothar Kimmeringer

In order to compile an application I can do: (I am on Windows)

javac name\mihaiu\test\CTest.java
javac name/mihaiu/test/CTest.java

That's a correct behavior, because here you compile a file.
That slashes are accepted on the Windows-machine because
of the accepting of slashes in the underlying java.io.File,
doing the system-dependent file-handling.
but when I run it I must do:

java name/mihaiu/test/CTest

because the backslash version FAILS:

java name\mihaiu\test\CTest

The backslashes won't work even if I am on a windows platform
! Why is this happening ? On windows the backslash is the separator.

Because the accepting of the slashes on java was introduced with
Java 1.2 (on 1.1 it didn't work) to ease the handling with the
autocompletition on Unix-systems. It seams that there is a
classFile = classFile.replace('/', '.') instead of the better
classFile = classFile.replace(File.separatorChar, '.')

I think because until Windows XP there was no official way of
acitvating an autocompletition on the console.

BTW: The official way to start aforementioned class is
java name.mihaiu.test.CTest
and will work on all systems no matter what even without the
concept of a filesystem (mobile phones for example).


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
K

Karl von Laudermann

In order to compile an application I can do: (I am on Windows)

javac name\mihaiu\test\CTest.java
javac name/mihaiu/test/CTest.java

This is because the "javac" command takes a file name as its
parameter. If you specify a file with its full path, you can use the
backslash as the path separator, which is the default in Windows.
Windows seems to accept forward slashes as well, though (as Flip
pointed out).
but when I run it I must do:

java name/mihaiu/test/CTest

because the backslash version FAILS:

java name\mihaiu\test\CTest

This is because the "java" command does *not* take a file name as its
parameter; it takes a *class* name. The parts before the class name
are not a path specifier, they are a *package* specifier. In Java, a
backslash is not a valid package separator; the valid package
separators are forward slash and period. In fact, this should work as
well:

java name.mihaiu.test.CTest
 
M

Mark McConnell

Hi!




In order to compile an application I can do: (I am on Windows)

javac name\mihaiu\test\CTest.java
javac name/mihaiu/test/CTest.java


but when I run it I must do:

java name/mihaiu/test/CTest

because the backslash version FAILS:

java name\mihaiu\test\CTest

I was always taught to do

java name.mihaiu.test.CTest

That's because name.mihaiu.test.CTest is a Class, not a filename, and
the argument to 'java' should be a Class.

If the / version works, it's some kind of extra bonus, not to be
relied on.
 
R

Razvan

Hi !


This is because the "java" command does *not* take a file name as its
parameter; it takes a *class* name. The parts before the class name
are not a path specifier, they are a *package* specifier. In Java, a
backslash is not a valid package separator; the valid package
separators are forward slash and period. In fact, this should work as
well:

java name.mihaiu.test.CTest

Now I understand. Indeed, I was trying to specify a file, not
the class. What puzzled me was the fact that you can use slashes ('/')
to specify the class. This can lead to the conclusion that you are
specifying a file instead of a class.



Regards,
Razvan
 
R

Razvan

Hi !


This is because the "java" command does *not* take a file name as its
parameter; it takes a *class* name. The parts before the class name
are not a path specifier, they are a *package* specifier. In Java, a
backslash is not a valid package separator; the valid package
separators are forward slash and period. In fact, this should work as
well:

java name.mihaiu.test.CTest

Now I understand. Indeed, I was trying to specify a file, not
the class. What puzzled me was the fact that you can use slashes ('/')
to specify the class. This can lead to the conclusion that you are
specifying a file instead of a class.



Regards,
Razvan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top