aspose file tools*
The moose likes Beginning Java and the fly likes Invalid Chararcter constant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Invalid Chararcter constant" Watch "Invalid Chararcter constant" New topic
Author

Invalid Chararcter constant

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
Can anyone explain why I get an Invalid character constant error with the following line of code
//char a = '\u000A';
+ Why does the above not compile but the following does
/*char a = '\u000A';*/
Any help would be truly appreciated
Tony
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

Tony,
Please re-register with a UserName that conforms to the JavaRanch Naming Policy. Thanks for your cooperation.
Unicode literals are translated very early on in the compilation process. '\u000A' happens to be the line feed and the result is that the compiler tries to compile
<pre>
// char a = '
';
not good because // is only for one line

/* char a = '
'; */
OK because /* */ spans lines
</pre>

------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform


Junilu - [How to Ask Questions] [How to Answer Questions]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
If you look at the Unicode Charts yout will see that \u000A is unicode for Line Feed.
Since the .java file is parsed before compiling, and all of the unicode literals are converted first, the input line is actually split into 2 lines by the LF.
Then as Junilu said, the // comment syntax does not include both of those lines.

"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid Chararcter constant