• 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

Unicode questions

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going through the SCJP2 notes and subsequent mock exams here and I'm getting answers that don't make sense to me. I was hoping someone could tell me why they are what they are.
(These are all from the first page)
Q17 An example unicode value is '0x3c0' in hexadecimal.
Which of the following correctly initializes the char primitive to the pi?
I say: b - char pi='\u03c0';
They say: a - char pi='u3c0';
I thought the Unicode value always began with a slash?
Q18 State the reason for a compile error caused by the following statement
String name="summertime \u00d wintertime";
I say: c - '\u00d' is not a valid unicode character
They say: b - escape sequences inserts the code for a line terminator. Line terminators are not allowed between opening and closing quotes
Since when can't you have a line break between quotes?
Thanks for any help,
g.
[ April 26, 2002: Message edited by: Garann Rose Means ]
[ April 26, 2002: Message edited by: Garann Rose Means ]
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The format of a unicode escape sequence is very, very strict. It's a back-slash, followed by one or more "u" characters, followed by exactly four hex characters (Ie, single digits in range of 0-9, a-f,or A-F).
So in your first example I'd agree with you that without the slash, it's not a unicode escape sequence.
The answer to the second question should be something like "\u00d" is NOT a valid unicode escape sequence since there are only THREE, not FOUR hex characters.
But, if it *were* \u000d, then this would also be a problem, because this would cause a line-feed character to be inserted in the stream before the text is parsed, and to the compiler it would look like you had typed:

and this would be a syntax error. You can't break strings across lines like this. Although you could do this:

so this might work, although I haven't tried it:
String name="summertime" + \u000d "wintertime";
[ April 26, 2002: Message edited by: Rob Ross ]
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Garann,
here is a post
that provides more examples.
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answers!
I had assumes any Unicode would modify the final output, not the code itself - thanks for correcting me.
 
I found some pretty shells, some sea glass and this lovely 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