It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes float f= \u0038 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "float f= \u0038 " Watch "float f= \u0038 " New topic

float f= \u0038

weiliu lili
Ranch Hand

Joined: Apr 11, 2002
Posts: 46
why this is valid? float f= \u0038
I thought the right way should be float f= 'u0038'
the explanation is that \u0038 is unicode for nbr 8. what does that mean?
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
You can read more about Unicode in the JLS, §3.10.4 Character Literals. In short, Unicode format encapsulates all characters in the World, unlike ASCII.
When you compile a Java program, Unicode characters are translated very early in the process. Therefore, when it actually came time to compile that code, the compiler would see the line:

This is obviously valid. Of course, had we put tick marks around it, we would have ended up with this:

This is also legal, but it's also quite different. The number 8 and the character value of the number 8 are not one in the same.
I hope that helps,
[ June 06, 2002: Message edited by: Corey McGlone ]

SCJP Tipline, etc.
I agree. Here's the link:
subject: float f= \u0038
It's not a secret anymore!