Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about Unicode!

 
laura_zpf
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Laura,
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.
 
kiran k
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic