GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unicode 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 "Unicode" Watch "Unicode" New topic
Author

Unicode

Malar Ravi
Ranch Hand

Joined: Oct 15, 2001
Posts: 51
______________________________________________________________
char A = '\u0005';
char B = 5;
if (A==B)
System.out.println("Equal ");
else
System.out.println("Not equal");

A = '\u0025';
B = 25;
if (A==B)
System.out.println("Equal ");
else
System.out.println("Not equal");
Output
------
Equal
Not equal
______________________________________________________________
Could someone explain me this code?
Thanks,
Malar.
Jennifer Warren
Ranch Hand

Joined: Aug 24, 2001
Posts: 53
do a little change in ur code and see it yourself.
char A = '\u0005';
char B = 5;
if (A==B)
System.out.println("Equal "+ A +" " +B);
else
System.out.println("Not equal");
A = '\u0025';
B = 25;
if (A==B)
System.out.println("Equal ");
else
System.out.println("Not equal"+ A +" " +B);

Hope it explains.
Jennifer.
Malar Ravi
Ranch Hand

Joined: Oct 15, 2001
Posts: 51
Hi Jennifer,
Thanks for your response. The point which I missed to understand before posting the previous code is that Unicode character is represented by \u followed by 4 hexadecimal digits.
A = '\u0025'
B = 25;
If I replace B=25 with B = 37; (equivalent of 0x0025) then I get "Equal" as output in my previous code.
- Malar.
guoyuan zhao
Greenhorn

Joined: Oct 09, 2001
Posts: 13
I am a new one,I don't know how the char convert to Unicode ,
Is your question means that [char 'u00xx']not always equals to [char xx]what is the relations?
Cristian Negresco
Ranch Hand

Joined: Sep 15, 2001
Posts: 182
Hi,
While watching:
char a = '\uxyzw';
every letter will be a HEXA value (0..F)
char b = n;
n it's in decimal.
So if (xyzw)base16 it is equal to (n)base10 so will be the characters.
..Cristian
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi guoyuan,
Each Unicode character maps to a specific character based on a given character set or character encoding.
For example, in the standard character set '\u0025' maps to '%', '\u0037' maps to '7', '\u0061' maps to 'a'.
To find out more about how it works see www.unicode.org. For a quicker overview check out this Unicode FAQ and try the the Unicode decoder
Hope that helps.
[This message has been edited by Jane Griscti (edited November 07, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
GeeCON Prague 2014
 
subject: Unicode