File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about 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 "A question about Unicode!" Watch "A question about Unicode!" New topic

A question about Unicode!

Ranch Hand

Joined: Sep 14, 2000
Posts: 30
public class EqualsTest{
public static void main(String args[]){
char A='\u0005';
if(A==0x0005L) System.out.println("Equal");
else System.out.println("Not Equal");
b) The program compiles and prints "Not Equal".
c) The program compiles and prints "Equal".
The answer is c). Could you tell me how to convert unicode char A='\u0005' to usual format? such as \u0005' is equals to 0x0005L. what is the meaning of the 'L' in the format?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Unicode characters are represented by their HEX value; so when you see '\udddd' the 'dddd' can be any HEX digit.
In the example '\u0005' in HEX is '0x0005'; just replace the Unicode escape chars '\u' with the Hex identifier '0x'.
The 'L' after '0x0005L' represents a 'long' primitive type (64-bit) vs an integer type (32-bit). I'm not sure why it's used in the example as Unicode is a 16-bit character set. The code will print 'Equals' if 'A==0x0005' is used.
Hope that helps.

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
kiran k

Joined: Sep 11, 2000
Posts: 3
in java a character is represented with unicode which is of 16-bit. A='\u0005' assigns a code equal to hexadecimal 0005. in the if statement an int A is compared to long constant which is represented in hexa-decimal notation. java compiler implicitly converts the int A into long then compares and returns the result which is obviously true and hence it prints "Equal".
I agree. Here's the link:
subject: A question about Unicode!
It's not a secret anymore!