javacompiler-errorscase-sensitive

Why isn't case a problem when compiling this Java file?


If I write a Java class as follows: public class Test {}

...and save it in a file with the same class name, but different case, like this: test.java

...then why is it possible to compile it successfully as follows: javac Test.java?

I thought the name of a public class and its file name must be the same, including in case. I am surprised I did not get a "file not found" error. What am I misunderstanding?


Solution

  • If you are compiling in an operating system with a file system that is not case sensitive like Windows the compiler will not notice the difference. That's because for the file system test.java and Test.java are the same file.