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, 09:59 AM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 45
Rep Power: 0
j2vdk is on a distinguished road
Thumbs up 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 01:15 PM. Reason: no replies
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-30-2008, 12:02 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 451
Rep Power: 2
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Default
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, 12:46 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 45
Rep Power: 0
j2vdk is on a distinguished road
Default
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, 12:49 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 45
Rep Power: 0
j2vdk is on a distinguished road
Default
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, 01:43 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 66
Rep Power: 0
ProjectKaiser is on a distinguished road
Default
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 01:52 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-30-2008, 01:58 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 66
Rep Power: 0
ProjectKaiser is on a distinguished road
Default
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, 02:11 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
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, 02:21 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 66
Rep Power: 0
ProjectKaiser is on a distinguished road
Default
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, 03:28 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,523
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
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.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
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.
Resources:
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.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
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, 04:08 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 66
Rep Power: 0
ProjectKaiser is on a distinguished road
Default
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, 04:15 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,523
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
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.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
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.
Resources:
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.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
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, 06:31 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 45
Rep Power: 0
j2vdk is on a distinguished road
Default
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, 06:37 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 45
Rep Power: 0
j2vdk is on a distinguished road
Default
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, 06:39 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 45
Rep Power: 0
j2vdk is on a distinguished road
Default
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, 06:40 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 45
Rep Power: 0
j2vdk is on a distinguished road
Default
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, 06:43 PM
Senior Member
 
Join Date: Jun 2008
Posts: 902
Rep Power: 2
masijade is on a distinguished road
Default
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, 06:50 PM
Senior Member
 
Join Date: Jun 2008
Posts: 902
Rep Power: 2
masijade is on a distinguished road
Default
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, 06:53 PM
Senior Member
 
Join Date: Jun 2008
Posts: 902
Rep Power: 2
masijade is on a distinguished road
Default
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, 07:00 PM
j2vdk's Avatar
Member
 
Join Date: Aug 2008
Posts: 45
Rep Power: 0
j2vdk is on a distinguished road
Default
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, 07:04 PM
Senior Member
 
Join Date: Jun 2008
Posts: 902
Rep Power: 2
masijade is on a distinguished road
Default
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
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Case Sensitive Problem techissue2008 Database 1 06-10-2008 06:23 AM
Case Based Reasoning kbyrne Advanced Java 4 04-12-2008 08:51 PM
problem with operator in case jimJohnson New To Java 2 03-21-2008 08:22 PM
String Title case bugger New To Java 4 01-28-2008 05:06 PM
Can I set a range in case statement? christina New To Java 1 07-25-2007 08:41 PM


All times are GMT +2. The time now is 02:28 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org