• 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

Reg. Unicode escape literals

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Unicode escape literals

Is that when we use then as literals value for assigning
to a character we cannot use their hexadecimal equivalent.
For eg:
char c = '\u000a' gives compile error.
so we have to use
char c = '\b';
Pls. correct if wrong and explain to me.
 
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
JLS 3.2 explains very well that topic...
but char c = '\u000a'; is not allowed because when compiled the line would look like this:
char c = '
'; //note the line break
Val
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to further Val's post, you cannot use '\u000A' or '\u000D' in a String literal or in single-line comments.
One of the first things the compiler does is evaulate Unicode literals. The above are intrepeted literally as 'newline' and 'carriage return'. They will break your code.
Always use '\n' and '\r'
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic