• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Valid char values!

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
i thought i am well prepared for the exam, but when i met that example, i undrestood i am not yet!
public class Test002 extends Super
{
public static void main(String args[])
{
char c1 = '\u00AA';
char c2 = '\u00DD';
char c3 = '\u000D';
char c4 = '\u000A';
}
}

can somone tell me why c1 and c2 are valid values wheras c3 and c4 are not!
Thank you in advance!
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by fethi makhlouf:

char c2 = '\u00DD';
char c3 = '\u000D';
char c4 = '\u000A';
}
}

can somone tell me why c1 and c2 are valid values wheras c3 and c4 are not!


Firstly,
/u000d represents carriage return
/u000a represents new line
Now the first thing that the compiler does is convert the unicode into the respective characters. This happens, I guess, even before the actual compilation process starts.
So the c3 and c4 lines when passed to the compiler would look like this

So ur code above is equivalent to the one below:

and hence the compile error.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic