View Poll Results: is this question sensible???

Voters
4. You may not vote on this poll
  • silly

    0 0%
  • good

    3 75.00%
  • excellent

    1 25.00%
Page 1 of 3 123 LastLast
Results 1 to 20 of 54
  1. #1
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    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 02:15 PM. Reason: no replies

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    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:
    Java Code:
    c
    bc

  3. #3
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    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:\>

  4. #4
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    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,,

  5. #5
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    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.

    Java 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 02:52 PM.

  6. #6
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    One more note - when I copypaste code to Eclipse it starts to rebuild entire worspace. Wow.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    "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!

  8. #8
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    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".

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  10. #10
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    Above I gave results from FreeBSD 6.3.
    Isn't it UNIX ? :)

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  12. #12
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    java is platform independent.. right....

    then how can u give this answer,,,

  13. #13
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    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();
    }
    }

  14. #14
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    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.

    Java 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,,,

  15. #15
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    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

  16. #16
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    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.

  17. #17
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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.)

  18. #18
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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:

    On FreeBSD 6.3-STABLE example compiles and runs well.

  19. #19
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    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,,,,

  20. #20
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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.

Page 1 of 3 123 LastLast

Similar Threads

  1. String Title case
    By bugger in forum New To Java
    Replies: 6
    Last Post: 01-31-2012, 02:21 PM
  2. MySQL Case Sensitive Problem
    By techissue2008 in forum JDBC
    Replies: 1
    Last Post: 06-10-2008, 07:23 AM
  3. Case Based Reasoning
    By kbyrne in forum Advanced Java
    Replies: 4
    Last Post: 04-12-2008, 09:51 PM
  4. problem with operator in case
    By jimJohnson in forum New To Java
    Replies: 2
    Last Post: 03-21-2008, 09:22 PM
  5. Can I set a range in case statement?
    By christina in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •