Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

View Poll Results: is this question sensible???
silly 0 0%
good 3 75.00%
excellent 1 25.00%
Voters: 4. You may not vote on this poll

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-30-2008, 11:59 AM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 41
j2vdk is on a distinguished road
Is Java Case Sensitive???? Prove It
java is case sensitive means, then y does the below code gets compile time error,,,,[ if any syntax error, dont take it, please see the main concept alone]

class c{
c(){
System.out.println("c");
}
}

class C extends c{
C(){
System.out.println("bc");
}
}

class a{
public static void main(String ar[]){
new C();
}
}

note: here i'm using two classes other than main class, with same letter , but one is small 'c', and other is caps 'C',,, this is case sensitive. the program gets compiled correctly, but y it gets an run time error?????.

please get me an answer as soon as possible,,,,

Thanks for reading it,,,,



y many are viewing the post, but no replying,,,,,,,,,,,,Is my question correct or all u dont know de answr,, no wrong in it, i want to all your suggestion ,,,, express your ideas,,, lets explore these questions... bcoz i too was challenged by this question, so help me,,,,

Last edited by j2vdk : 08-30-2008 at 03:15 PM. Reason: no replies
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-30-2008, 02:02 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 321
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
What error do you get,i ceated three class in three different files,and it compiled and ran without any error and got the output:
Code:
c bc
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-30-2008, 02:46 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 41
j2vdk is on a distinguished road
y creating seperate file for each class,,,,, keep entire code in single notepad,,, i saved it as case.java,,,,,,,
got compiled correctly,,,
if run means,i get this error....




D:\>javac case.java

D:\>java a
Exception in thread "main" java.lang.NoClassDefFoundError: c (wrong name: C)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at a.main(case.java:15)

D:\>
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-30-2008, 02:49 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 41
j2vdk is on a distinguished road
thank you replying me, with an answer,,,

but can u tell how can we write each class in seperate file,, an how execute in this case, so tat i can try it,,
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-30-2008, 03:43 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
Funny.

On Windows XP, FAT32, Eclipse it gives compilation time error:
Class file collision: A resource exists with a different case: /server/bin/misc/java_forums/C.class.

On FreeBSD 6.3-STABLE example compiles and runs well.

Code:
> java a c bc
I think it is potentially dangerous to give identical case insensitive names to few classes in the same package. Java is somehow system-dependent here, since it puts classes to files and it may come to hell as soon as not all filesystems are case-sensitive.

Last edited by ProjectKaiser : 08-30-2008 at 03:52 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-30-2008, 03:58 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
One more note - when I copypaste code to Eclipse it starts to rebuild entire worspace. Wow.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-30-2008, 04:11 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
"main" java.lang.NoClassDefFoundError: c (wrong name: C)
That looks like an OS that is not case sensitive, like windows.
You can NOT have the files: c.class and C.class in the same folder!
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-30-2008, 04:21 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
Indeed, Norm, you are right. Say it compiles first class "c" then class "C". File c.class gets overrided and oops - class "C" can not be instantiated anymore, since it is inherited from "c".
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 08-30-2008, 05:28 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by ProjectKaiser View Post
Indeed, Norm, you are right. Say it compiles first class "c" then class "C". File c.class gets overrided and oops - class "C" can not be instantiated anymore, since it is inherited from "c".
Yep, this is the correct reason. Simply files are replaced from another. This is not a good choice actually. So in naming conventions, don't use same class names depend on case sensitivity. Avoid all the time.

But one thing I'm not sure, in Linux is this happened. I'll check it later, because I think it wont happen in UNIX systems.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 08-30-2008, 06:08 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
Above I gave results from FreeBSD 6.3.
Isn't it UNIX ?
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 08-30-2008, 06:15 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Hmm, so it's not work at all. Anyway the best thing is avoid same cases in naming.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 08-30-2008, 08:31 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 41
j2vdk is on a distinguished road
java is platform independent.. right....

then how can u give this answer,,,
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 08-30-2008, 08:37 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 41
j2vdk is on a distinguished road
Quote:
Originally Posted by Norm View Post
That looks like an OS that is not case sensitive, like windows.
You can NOT have the files: c.class and C.class in the same folder!
u said-"tat looks like OS", cant underswtand this ...

if im giving names as c and C then it wont work, are u saying this??


suppose i give names cat & CAT as clas names- i get same error while executing,,,, but gets compiled...



TRY THIS::::: and tell me.... y im asking u is,i was asked this question an cant find the solution....anyway thanx for replying...

class cat{
cat(){
System.out.println("cat");
}
}
class CAT extends cat{
CAT(){
System.out.println("CAT");
}
}
class a{
public static void main(String ar[]){
new CAT();
}
}
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 08-30-2008, 08:39 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 41
j2vdk is on a distinguished road
Quote:
Originally Posted by ProjectKaiser View Post
Funny.

On Windows XP, FAT32, Eclipse it gives compilation time error:
Class file collision: A resource exists with a different case: /server/bin/misc/java_forums/C.class.

On FreeBSD 6.3-STABLE example compiles and runs well.

Code:
> java a c bc
I think it is potentially dangerous to give identical case insensitive names to few classes in the same package. Java is somehow system-dependent here, since it puts classes to files and it may come to hell as soon as not all filesystems are case-sensitive.
java is platform independent.. right....

then how can u give this answer,,,
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 08-30-2008, 08:40 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 41
j2vdk is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Yep, this is the correct reason. Simply files are replaced from another. This is not a good choice actually. So in naming conventions, don't use same class names depend on case sensitivity. Avoid all the time.

But one thing I'm not sure, in Linux is this happened. I'll check it later, because I think it wont happen in UNIX systems.
i wont use normally,, but i was questioned like this,,, cant find solution... so please tell the reason for runtime error
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 08-30-2008, 08:43 PM
Senior Member
 
Join Date: Jun 2008
Posts: 469
masijade is on a distinguished road
Java is case sensitive, but classes will be compiled and each one stored as a file. If the OS, then, is not case sensitive when it comes to the file system, then, if the classes are in the same package (therefore in the same directory), it will not work, because during compilation one class (whichever of the two is compiled last) will overwrite the other.
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 08-30-2008, 08:50 PM
Senior Member
 
Join Date: Jun 2008
Posts: 469
masijade is on a distinguished road
Quote:
Originally Posted by j2vdk View Post
java is platform independent.. right....

then how can u give this answer,,,
Java is "platform independent". I.E., code written on one machine, will run on every other machine for which a JVM (a java installation) exists. There are some limitations, however.

The above can be one of them. If, however, the files were compiled on an OS that is case sensitive and packed into a jarfile, that jarfile can then be used on an OS that is not case sensitive, because the Classes will be contained within the jarfile and, therefore, not contingent on the OS filesystems case sensitivity.

Another limitation is the use of Runtime.exec() or ProcessBuilder. If you use those, there is a 99.9999999999999% chance that the code is not platform independent. This can be gotten around, somewhat, by placing the commands to use in properties files (or something to that effect) and having one for each OS, as long as you are displaying the output of the commands, or executing a function. If the program tries to evaluate what the command produces, then much more work would need to be done to accomplish any kind of platform independence for that sort of thing. (A plugin architecture for that portion, maybe.)
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 08-30-2008, 08:53 PM
Senior Member
 
Join Date: Jun 2008
Posts: 469
masijade is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Hmm, so it's not work at all. Anyway the best thing is avoid same cases in naming.
He said the following:

Quote:
On FreeBSD 6.3-STABLE example compiles and runs well.
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 08-30-2008, 09:00 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 41
j2vdk is on a distinguished road
Quote:
Originally Posted by masijade View Post
Java is case sensitive, but classes will be compiled and each one stored as a file. If the OS, then, is not case sensitive when it comes to the file system, then, if the classes are in the same package (therefore in the same directory), it will not work, because during compilation one class (whichever of the two is compiled last) will overwrite the other.
dont misunderstand me- one doubt----

im writing this program in single notepad, named case.java,,,, if i compile it i get single .class file, ie. case.class file,,,,

so only one .class file present,,,, how c.class and C.class will overwrite thennn
thanx for replying,,,,
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 08-30-2008, 09:04 PM
Senior Member
 
Join Date: Jun 2008
Posts: 469
masijade is on a distinguished road
Quote:
Originally Posted by j2vdk View Post
dont misunderstand me- one doubt----

im writing this program in single notepad, named case.java,,,, if i compile it i get single .class file, ie. case.class file,,,,

so only one .class file present,,,, how c.class and C.class will overwrite thennn
thanx for replying,,,,
I already answered this for you in your other thread.

You have three class definitions (not classes) in a single java (i.e. source code) file. When this file is compiled, each of the compiled classes created from those class definitions, as they are compiled, will be placed into their own class (i.e. byte code/compiled/binary/however you want to refer to them) file. Therefore, one java source code file and three compiled binary class files.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes
Linear Mode Linear Mode