User27854
User27854

Reputation: 884

Why is the Java compiler (javac) case-insensitive when java (the interpreter) is case-sensitive?

When I was executing a Java program I noticed that the Java compiler is case-insensitive with respect to file names whereas the Java interpreter is case-sensitive.

The Java interpreter being case-sensitive is very much understandable as, the name of the class file is the name of the class defined in the Java code.

Is there any good reason for the Java compiler being case-insensitive?

Upvotes: 2

Views: 1647

Answers (4)

David Conrad
David Conrad

Reputation: 16359

Presumably you're running the compiler on Windows or another operating system with either a case-preserving or case-insensitive filesystem. If you ran it on an OS that used a case-sensitive filesystem, you would get different results. In other words, it's not the compiler, it's the operating system (or rather, its filesystem).

Upvotes: 3

Ingo
Ingo

Reputation: 36339

Windows is still an OS for children and people that just want to surf the Web or do their fiscal paperwork. But not for developers.

Since almost 20 years, MS has done almost nothing with respect to:

  • File systems (they could keep their beloved NTFS as default, and offer another one for professionals, could they not)
  • Command line, it's still the same bad crap we got with Windows NT. Mind you, NT stands for "New Technology" and yet they didn't even manage to inherit what was already available for another 10 or 20 years.

Hence, if you develop Java, make sure you don't have class or package names that differ in case only. This will invariably lead to disaster.

Do yourself a favor, make a bit room on your HD, or attach an external one, and install a dual boot LINUX. If must be, make a virtual machine. You'll never look back, once you got your favored IDE installed. And you'll learn a bit or two along the way.

Upvotes: 3

JVMATL
JVMATL

Reputation: 2122

it depends on the underlying file system. Windows' file system is not case sensitive, so the when the java compiler looks for 'Foo.java', the OS will happily open 'foo.java' instead.

Upvotes: 3

SLaks
SLaks

Reputation: 887449

The Windows filesystem is case-insensitive.
You cannot (sanely) find a case-sensitive file on a case-insensitive filesystem.

If you run javac on Linux with a case-sensitive filesystem, it will be case-sensitive.

Upvotes: 7

Related Questions