• 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

uni code

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i compile this code i receive an error message
char c = '\u000a';
even when i comment this line like this
// char c = '\u000a';
still there is an error.
it does not accept comment on this line
why is it so ? and what's the error in this statement?
 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow.. weird. You're right! Even if its in a comment, it won't accept it. Must be a bug. I did b and it worked. Hmmm...
char c = '\u000b';
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )
[This message has been edited by Dale DeMott (edited July 11, 2001).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope - no bug. The sequence that you used is the unicode equivalent of a linefeed. Since the codes are converted to their values BEFORE the syntax is compiled, that unicode was replaced with the linefeed, creating a file that looked like:
// char c = '
';
The first line is commented out, but not the second line, and that is invalid syntax, therefore the error.

From the Java Language Specification:


The character and string escape sequences allow for the representation of some nongraphic characters as well as the single quote, double quote, and backslash
characters in character literals (�3.10.4) and string literals (�3.10.5).
EscapeSequence:
\ b = /* \u0008: backspace BS */
\ t = /* \u0009: horizontal tab HT */
\ n = /* \u000a: linefeed LF */
\ f = /* \u000c: form feed FF */
\ r = /* \u000d: carriage return CR */
\ " = /* \u0022: double quote " */
\ ' = /* \u0027: single quote ' */
\ \ = /* \u005c: backslash \ */


Therefore if you WANT to put a linefeed in your char you must use the supplied substitute instead.
So you should have coded:
// char c = '\n';
[This message has been edited by Cindy Glass (edited July 11, 2001).]
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Babar
I think it may have somehting to with the fact that one of the fiorst things the compiler does is transform all of the unicode escapes in the file. Thats why this line of code is valid

it becomes

I think what is happening is that it transforming the \u000a into a line feed (that's what 000a is) and then complains that you have a line feed in the middle of your declaration. To the compiler it probably looks like this

Dales' example worked because 000b is a tab.
hope this helped
Dave

Cindy types faster than I do She also probably didn't have to go to the jls to make sure she was right

[This message has been edited by Dave Vick (edited July 11, 2001).]
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OH yes I did .
 
Babar Saeed
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a lot David
and Cindy Glass
now i'm clear about the code
//char c = '\u000a';
Again thanx a lot for ur cooperation.
 
Babar Saeed
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a lot David
and Cindy Glass
now i'm clear about the code
//char c = '\u000a';
Again thanx a lot for ur cooperation.
 
reply
    Bookmark Topic Watch Topic
  • New Topic