Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Character literals

 
prarthana reddy
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
// unicode value for character a is \u0061.

public class Test
{
public static void main(String args[])
{
System.out.println((char)('\u0061') + " ");

System.out.println((int )('\u0061') + " ");

System.out.println((char)('a') + " ");

System.out.println((int)('a'));
}
}

Answer for the above is a,97,a,97....why is it 97 when converted to int? mat be this is a basic question but i want to make clear..
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the ASCII value of 'a'.

Also 61 base 16 = 97 base 10.
[ August 15, 2006: Message edited by: Keith Lynn ]
 
prarthana reddy
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are unicode literals represented in hexadecimal notation?
public class Test
{

public static void main(String args[])
{
System.out.println('\u033');
}

}
Why is the above code giving error ? What is the range of unicode literals ?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by prarthana reddy:
Are unicode literals represented in hexadecimal notation?
public class Test
{

public static void main(String args[])
{
System.out.println('\u033');
}

}
Why is the above code giving error ? What is the range of unicode literals ?


The problem here is that a char literal is 16 bits, but 033 is only 12 bits.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic