Results 1 to 6 of 6

Thread: char datatype

  1. #1
    frejon26 is offline Member
    Join Date
    Jan 2008
    Posts
    14
    Rep Power
    0

    Default char datatype

    Why does the following char assignment produce an error?
    Java Code:
    char myChar = '\u000a';
    When the following char assignment does not?
    Java Code:
    char myChar = '\u000b';

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

    Default

    What error? 0A is a Line Feed whereas 0B is a Vertical Tab. See http://www.unicode.org/charts/PDF/U0000.pdf.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by frejon26 View Post
    Why does the following char assignment produce an error?
    Java Code:
    char myChar = '\u000a';
    When the following char assignment does not?
    Java Code:
    char myChar = '\u000b';
    The compiler scans input text for \uXXXX sequences before anything else and translates those sequences to the characters they represent; your program text ends up as:

    Java Code:
    char myChar = '
    ';
    Your \u000a sequence was translated to a real newline character; the resulting text doesn't make up valid program text; that is where those symbolic representations come up: \n for \u000a and \r for \u000d etc.

    kind regards,

    Jos

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

    Default

    Ah ya. Forgot again that the unicode is translated first. I'm still an idiot sometimes (more often than is comfortable, in fact).

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by masijade View Post
    I'm still an idiot sometimes (more often than is comfortable, in fact).
    You're not my long lost twin brother are you? ;-)

    kind regards,

    Jos

  6. #6
    frejon26 is offline Member
    Join Date
    Jan 2008
    Posts
    14
    Rep Power
    0

    Default

    thanks guys, I didn't know it was translated before it was assigned... good deal

Similar Threads

  1. replaceALL(char oldChar, char newChar) method
    By arson09 in forum New To Java
    Replies: 0
    Last Post: 04-28-2010, 06:48 AM
  2. how to find a datatype
    By hasysf in forum New To Java
    Replies: 1
    Last Post: 09-06-2009, 11:41 AM
  3. Problem in using Object datatype
    By mfaizan24 in forum New To Java
    Replies: 6
    Last Post: 05-06-2009, 12:51 AM
  4. drawing char by char with Graphics
    By diggitydoggz in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 01:49 PM
  5. Problems with a complex datatype in a webservice
    By lichtbringer in forum Web Frameworks
    Replies: 2
    Last Post: 10-29-2008, 06:32 AM

Posting Permissions

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