aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Query on Source File name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Query on Source File name " Watch "Query on Source File name " New topic
Author

Query on Source File name

Thulasi Arasu
Greenhorn

Joined: Apr 20, 2009
Posts: 10
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

Joined: Apr 03, 2009
Posts: 49
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!


scjp6-90%
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1212
    
    1

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

Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1212
    
    1

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

Joined: Apr 20, 2009
Posts: 10
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

Joined: Apr 20, 2009
Posts: 10
Agarwal

I missed your latest reply , so this post.
Your explanation make sense to me.
Thanks again.
 
 
subject: Query on Source File name