aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Character literals 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 "Character literals" Watch "Character literals" New topic
Author

Character literals

prarthana reddy
Ranch Hand

Joined: Jul 24, 2006
Posts: 48
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

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Jul 24, 2006
Posts: 48
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

Joined: Feb 07, 2005
Posts: 2367
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Character literals