| Author |
Question from Dan's test on Char values
|
Veena Pointi
Ranch Hand
Joined: Jun 20, 2002
Posts: 442
|
|
class D { public static void main (String[] args) { char a = 061; // 1 char b = '\61'; // 2 char c = '\061'; // 3 char d = 0x0031; // 4 char e = '\u0031'; // 5 System.out.print(""+a+b+c+d+e); } } Ans:Compiles & runs fine. At line one octal integer is converted to char. At line 4 hexadecimal integer is assigned. At line 5 unicode character is assigned. But I am not understanding what is happening at lines 2 & 3?What is the role of back slash there? Thanks Veena
|
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
|
 |
Damien Howard
Ranch Hand
Joined: Apr 01, 2003
Posts: 456
|
|
both lines 2 and 3 are octals also. The backslash allows you to place the octal digits there. I asked a similar question a couple weeks ago. If you do a search you should be able to find it. I think someone posted a link when they responded explaining it. I wouldn't worry about it being on the exam though.
|
 |
Marlene Miller
Ranch Hand
Joined: Mar 05, 2003
Posts: 1391
|
|
'\001' '\01' '\1' '\012' '\12' "This is \u0061 string of text with escape sequences for some of the ch\141racters.\n" Some ASCII characters we can type �A� �a� �0� �*� Some ASCII characters we cannot type. So we use escape sequences instead. �\n� �\r� �\\� �\�� �0� is the decimal digit 0. How do we represent binary 0? We can use octal escape sequences to type any ASCII character. �\000� �\007� �\017� �\077� �\177� �\377� What are octal escape sequences good for? Control characters for data communications (end-of-text, end-of-line) and talking to devices (ring-bell, form feed) There are 65536 Unicode characters. Only the first 256 Unicode characters can be represented by octal escape sequences. (Actually, I think there are at least 90,000 currently defined Unicode characters.) [ July 18, 2003: Message edited by: Marlene Miller ]
|
 |
Veena Pointi
Ranch Hand
Joined: Jun 20, 2002
Posts: 442
|
|
Originally posted by Marlene Miller: '\001' '\01' '\1' '\012' '\12' "This is \u0061 string of text with escape sequences for some of the ch\141racters.\n" Some ASCII characters we can type �A� �a� �0� �*� Some ASCII characters we cannot type. So we use escape sequences instead. �\n� �\r� �\\� �\�� �0� is the decimal digit 0. How do we represent binary 0? We can use octal escape sequences to type any ASCII character. �\000� �\007� �\017� �\077� �\177� �\377� What are octal escape sequences good for? Control characters for data communications (end-of-text, end-of-line) and talking to devices (ring-bell, form feed) There are 65536 Unicode characters. Only the first 256 Unicode characters can be represented by octal escape sequences. (Actually, I think there are at least 90,000 currently defined Unicode characters.) [ July 18, 2003: Message edited by: Marlene Miller ]
Does '\0some number' & '\some number' represent octal representation?& '\u0some number' represent hexadecimal?
|
 |
 |
|
|
subject: Question from Dan's test on Char values
|
|
|