aspose file tools*
The moose likes Beginning Java and the fly likes uni code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "uni code" Watch "uni code" New topic
Author

uni code

Babar Saeed
Greenhorn

Joined: Jul 06, 2001
Posts: 13
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?
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
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).]


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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).]


"JavaRanch, where the deer and the Certified play" - David O'Meara
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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).]


Dave
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
OH yes I did .
Babar Saeed
Greenhorn

Joined: Jul 06, 2001
Posts: 13
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

Joined: Jul 06, 2001
Posts: 13
Thanx a lot David
and Cindy Glass
now i'm clear about the code
//char c = '\u000a';
Again thanx a lot for ur cooperation.
 
 
subject: uni code