aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes char declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "char declaration" Watch "char declaration" New topic
Author

char declaration

Harvinder Singh
Ranch Hand

Joined: Feb 14, 2003
Posts: 90
class char_declaration {
public static void main (String[] args) {
char a = 061;
char b = '\61';//1
char c = '\061'; //2
char d = 0x0031;
char e = '\u0031';
char f = 034;
char g=200;//this works
System.out.print(""+a+b+c+d+e+f+g);
}
}
//I can't understand how these two lines(1 And 2) are legal ways to declare
//char.plz tell me the general rule so that I don't make mistake in declaring char using octal format.A octal has leading zero that i know:-).
thanks.
/*
Reason given in the Chisholm answer:
All of the declarations are legal.
The first three are declared in octal format.
The fourth is declared as a hexadecimal literal.
The fifth is a unicode escape sequence. �
*/


Hard work beats talent<br />when talent doesn't work hard.<p> - Tim Notke
venu gopal
Ranch Hand

Joined: Nov 21, 2000
Posts: 40
Hi Harvinder,
I think you can get your answer from this.
3.10.6 Escape Sequences for Character and String Literals
The character and string escape sequences allow for the representation of some nongraphic characters as well as the single quote, double quote, and backslash characters in character literals (�3.10.4) and string literals (�3.10.5).
EscapeSequence:
\ b/* \u0008: backspace BS */
\ t/* \u0009: horizontal tab HT */
\ n/* \u000a: linefeed LF */
\ f/* \u000c: form feed FF */
\ r/* \u000d: carriage return CR */
\ "/* \u0022: double quote " */
\ '/* \u0027: single quote ' */
\ \/* \u005c: backslash \ */
OctalEscape/* \u0000 to \u00ff: from octal value */
OctalEscape:
\ OctalDigit
\ OctalDigit OctalDigit
\ ZeroToThree OctalDigit OctalDigit
OctalDigit: one of
0 1 2 3 4 5 6 7
ZeroToThree: one of
0 1 2 3
It is a compile-time error if the character following a backslash in an escape is not an ASCII b, t, n, f, r, ", ', \, 0, 1, 2, 3, 4, 5, 6, or 7. The Unicode escape \u is processed earlier (�3.3). (Octal escapes are provided for compatibility with C, but can express only Unicode values \u0000 through \u00FF, so Unicode escapes are usually preferred.)


char b = '\61';//1 It's in the limit . It can be upto '\377'.
char c = '\061'; //2 It's in the limit . It can be upto '\377'.

Thanks,
Venu Gopal.
[ August 16, 2003: Message edited by: venu gopal ]
Harvinder Singh
Ranch Hand

Joined: Feb 14, 2003
Posts: 90
Hi Venu,
thanks for ur help.I hope that I won't repeat mistake in doing that again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: char declaration