This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes character literals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "character literals" Watch "character literals" New topic
Author

character literals

natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
What is the problem with the following simple code. I get compile time error:
public class ADirtyOne
{
char a = '\u000a';
}

while
char a = '\u007a'; compiles properly.
TIA

Sun Certified Programmer for Java 2 Platform
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
This has been discussed before, so if you need more explanation, do a search for 'u\000a'.
Basically it is because what does 'u\000a' represent? It is the new line feed. So when the compiler goes through the code, the first thing it does is replace all the unicode with the literal meaning, so you replace 'u\000a' with a line feed. Then you get:
char a =
;
which won't compile.
Bill
Anshuman Acharya
Ranch Hand

Joined: Jan 19, 2001
Posts: 144
the same goes for char = '\u000d'
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
I read in the JLS, that the unicode escape sequence based char literals are processed at the earliest. So that's why '\u000a' is processed immediately and the ; in the end is taken to the next line.
Bye,
Tualha Khan


SCJP2, BEA WLS 6.0, DB2 UDB 7.1
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: character literals
 
Similar Threads
Why this output in this I/O program?
Reg. Casting rules
Difference between String.copyValueOf(char[]) and String.valueOf(char[])
Overloading and type conversion
Operators