This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Character literals
 
Similar Threads
chars
deal all, i have finished my mock exam 3, please take a look.
what is the difference?
ASCII - UNICODE
IS THIS LEGAL