Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6420
| Date | 2011-07-22 17:29 -0400 |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: CLI Java Glitch |
| References | <meevv65a675khs5c9goa9sp6f2hotf1321@4ax.com> <itogee$k8r$1@localhost.localdomain> <4dffe2ea$0$57121$c30e37c6@exi-reader.telstra.net> <alpine.DEB.2.00.1106212245430.6476@urchin.earth.li> <96dvubFalpU1@mid.individual.net> |
| Message-ID | <4e29ebb1$0$305$14726298@news.sunsite.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
On 6/22/2011 6:54 AM, Nigel Wade wrote:
> On 21/06/11 22:49, Tom Anderson wrote:
>> On Tue, 21 Jun 2011, Esmond Pitt wrote:
>>
>>> On 21/06/2011 8:09 AM, Martin Gregorie wrote:
>>>
>>>> The Java language system does case-sensitive comparisons between class
>>>> names and the files that contain them when checking that a class name
>>>> matches the file name that contains it
>>>
>>> Nitpicking, but it doesn't really do that, does it. It opens a .class
>>> file of the name the user specified, loads the class(es) it contains,
>>> and tries to find the classname it was looking for among those
>>> classes. It doesn't explicitly compare the filename and the classname.
>>> The operating system gave it HelloWorld.class in response to
>>> 'helloworld.class' because that's how the OS file system happened to
>>> work.
>
>>
>> The way Java does this at the moment means that 'java helloworld', where
>> there is no class 'helloworld', does different things on Windows
>> depending on whether there is a class HelloWorld, hElLoWoRlD,
>> HelloworlD, etc.
>
>
> Does it? What different thing does it do?
>
> As far as a case-insensitive OS/filesystem is concerned, they would all
> appear as the same file. If Java asked for any of those names from the
> filesystem it would get the one file which did exist for any of the
> class names. It would then look in that file for the class it required.
> If the class did not exist in that file it would throw the
> ClassNotFoundException. It cannot do anything else because the
> OS/filesystem simply will not allow it.
The argument is a class name not a file name.
And even on Windows you can have helloworld, HelloWorld and hELLOwORLD.
Classpath is not restricted to current directory.
You can have each of the above class files in different directories
or jar files.
>> That seems pretty shoddy to me. If you're a case-sensitive program
>> running on a case-insensitive operating system, i think it falls on you
>> to pay special attention to case in your dealings with that system: when
>> java opens a class file, it ought to check that the name of the file
>> it's opened actually has the right case, and if it doesn't, discard it,
>> and act as if it had got a file not found error from the operating system.
>
> But Java cannot do this. On a case-insensitve OS/filesystem it simply
> may not be possible for a file to exist called HelloWorld.class.
It does not need to.
OpenVMS with an ODS-2 disk system has all uppercase file names.
You write:
java "HelloWorld"
and Java find HELLOWORLD.CLASS !
> Java is not doing anything wrong. The user is, in assuming that because
> the OS/filesystem is case-insensitive that Java is also. The java
> command syntax is "java<ClassName>" not "java<filename>".
Yes.
> That class
> name is case sensitive, no matter how brain dead the OS or filesystem.
> If you ask Java to run the class helloworld when your class is actually
> HelloWorld, you have asked it to do the wrong thing. Java is perfectly
> correct in telling you this.
>
> If you ask Java to run the class HelloWorld, it does so even on a
> case-insensitive system such as that of the OP. Even if the file is
> called helloworld.class Java still manages to do the right thing.
Yes.
Arne
Back to comp.lang.java.programmer | Previous | Next | Find similar
Re: CLI Java Glitch Arne Vajhøj <arne@vajhoej.dk> - 2011-07-22 17:29 -0400
csiph-web