1. Hey Guest Did you know you can win an Honor 10 phone worth ₹33,000 and an additional ₹70,000 in paytm vouchers, just by replying to some threads and taking part in the discussions happening in the Honor Hub?

    What are you waiting for? Start commenting and start winning! Remember to read the instructions posted here.

    Dismiss Notice

I got a JAVA Problem

Discussion in 'QnA (read only)' started by ajayNCSTian, Sep 9, 2004.

Thread Status:
Not open for further replies.
  1. ajayNCSTian

    ajayNCSTian New Member

    Joined:
    Sep 9, 2004
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello Everybody

    Why following Commented Statement JAVAC cannot compile ??

    public class Unicode
    {
    public static void main(String[] args)
    {
    //char a = '\u007';
    /*char b = '\u007'*/;
    }
    }

    It is understandable that Unicode escape should follow 4 digits after it
    But why such a rule in commented statement ?
    What is the reason behind this :?:
     
  2. sujithtom

    sujithtom New Member

    Joined:
    Aug 14, 2004
    Messages:
    512
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    Not anywhere near you
    I am no Java programmer but I don't think you can use the name Unicode as it is a reserved word. Specify you error message
     
  3. OP
    OP
    ajayNCSTian

    ajayNCSTian New Member

    Joined:
    Sep 9, 2004
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Oops My mistake ... :wink:
    The Error message is :
    "Illegal Unicode character." at line <so and so>

    The class name is not taken by intension. I mean to say whatever you
    take class name .. Error remains the Same.

    Now how about it? :?
     
  4. GNUrag

    GNUrag FooBar Guy

    Joined:
    Jun 22, 2004
    Messages:
    1,246
    Likes Received:
    5
    Trophy Points:
    0
    Location:
    Interwebs
    The javac compiler makes several passes on the source code before it even checks keywords and classes... In this case, '\u007' is not a valid unicode character...

    Since u're doing a program in Unicodes, you should know that unicode escape sequences are composed of a leading \u and four HEX characters...

    Even when the code is commented, it will give error since, all the code is first parsed and all the unicode/hex/octal escape sequences are checked before actually compiling it...
     
  5. #/bin/sh

    #/bin/sh New Member

    Joined:
    Apr 20, 2004
    Messages:
    213
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    42.65 N 73.76 W
    Unicode characters are valid characters even in for your source code. Thus, the compiler sees the \u and expects a valid unicode.

    Insert the following line and see that the compiler flags the last '; as an invalid constant character.

    // char c = '\u000A';

    \u000A is a linefeed and thus the '; begins a new source line which is a compile error.

    \u followed by 4 hexadecimal characters!
    Now, // String a ="sasasas\uasasasas";
     
  6. #/bin/sh

    #/bin/sh New Member

    Joined:
    Apr 20, 2004
    Messages:
    213
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    42.65 N 73.76 W
    The problem is just with \u in comments

    even the strings like
    // String a ="sasasas\uasasasas";
    will not work
     
Thread Status:
Not open for further replies.

Share This Page