• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How is ch\u0061r a ='a'; valid?

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is ch\u0061r a ='a'; valid?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
During the lexical translation of a Java source file, all Unicode escapes are transformed to their Unicode character counterpart, that is
ch\u0061r a ='a';
is transformed to
char a = 'a';
char \u0061r ='a';
and
char a = '\u0061';
would also be valid.
See JLS 3.2 Lexical Translations for more details.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yup -- if you really really wanted -- you could write your ENTIRE program in Unary characters (that'd really promote maintainability and readability, don't ya think?) But that's just sillyness. However, I would expect a question having to do with it somehow on the exam. You're not expected to memorize all the characters, but you should know that its legal to use them.
Just as a real life example, I've used Unary characters in our Application Server when dealing with Internationalization and multi-byte characters (Japanese, Korean, etc).
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Valentin,
I saw this question in Khalid Mughals Book.
ch\u0061r a ='a';
What is the purpose of the a before the = symbol.
Doesn't it become char a a = a ?
I am a little confused?
Thanks
Pallavi
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In
ch\u0061r a ='a';
the a before the = sign is the variable name.
If you look carefully and replace the Unicode escape \u0061 with the Unicode character a, you should get
char a = 'a';
[ February 06, 2003: Message edited by: Valentin Crettaz ]
 
Pallavi Chakraborty
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Valentin,
Thanks so much.
I totally missed it.
ch \u0061 r = char
Thank you once again
Pallavi
 
reply
    Bookmark Topic Watch Topic
  • New Topic