I have a question.
It might seem as a trivial one. But it is still nagging.
When I compiled my source file with the case difference (original: HelloWorld; compiled it as Helloworld), it was fine and compiled
But while running, it throws the exception at main method.
What is the logic behind this?
I am using jdk 6.0
There is no issue of having literals with different cases. Im pretty sure that is something else. Btw, when using cases, you are saying that it compile but throws an exception, or it didn't compile?
If you post the code, I will definitely take a look on it!
When we use javac command , we are actually trying to run a java file , not java class itself.
So , let us say that my above mentioned code was saved in "HelloWorld.java" file.
Now , we can use below mentioned javac command to compile this class for eg
a. javac HelloWorld.java
b. javac Helloworld.java
c. javac helloworld.java
all above three command will be success and class will get compile .
REASON was Windows environment is by default case insensitive. So , when we run any of the above mentioned javac command , actually , javac command search for file mentioned as an argument and Window's case insensitive feature make javac command to successfully find this file (even if file name case is different ).
But , when we are running the compiled class with java command , here , JVM actually search for a class whose name is mentioned in argument of java command
here , JVM search for "Helloworld" class but since JAVA language is case sensitive , so , JVM is not able to find a class whose name is 'Helloworld'.
so , we have to give exactly same name of class as an argument to java command.
More over, I think , since UNIX environment is CASE - SENSITIVE , so if we try to compile same file on UNIX environment where JAVA is installed , there , javac command such as
will not work.
Joined: Apr 20, 2009
Fonseca and Agarwal, Thanks for your replies.
Agarwal had given it crystal clear. That is what I have faced too.
Hope I have answered it clearly.
Joined: Apr 20, 2009
I missed your latest reply , so this post.
Your explanation make sense to me.