• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query on Source File name

 
Thulasi Arasu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

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

I would really appreciate your help.
Thanks

Thulasi
 
armando fonseca
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Suppose we have a program as



Now , when i compile it with command as

a. javac HelloWorld.java
b. javac Helloworld.java
c. javac helloworld.java

all above three command were success and class was compiled

Now , when we try to run it with command as

a. java helloworld
It gave exception as "Exception in thread "main" java.lang.NoClassDefFoundError: helloworld (wrong name: HelloWorld)"

b. java Helloworld
It gave exception as "Exception in thread "main" java.lang.NoClassDefFoundError: helloworld (wrong name: HelloWorld)"


c. java HelloWorld
It ran successfully and "aaaaa" was printed on commadn prompt


So, even , i would also like to know why there is no case sensitive check for javac command.

P.S. - Above code was compiled on Windows enivornment


Thanks
Abhay Agarwal
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

One point actually striked me about this .....

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

for eg

java Helloworld
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
javac Helloworld.java
or
javac helloworld.java
will not work.

Thanks
Abhay Agarwal
 
Thulasi Arasu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fonseca and Agarwal, Thanks for your replies.

Fonseca,
Agarwal had given it crystal clear. That is what I have faced too.
Hope I have answered it clearly.

 
Thulasi Arasu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agarwal

I missed your latest reply , so this post.
Your explanation make sense to me.
Thanks again.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic