Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char declaration

 
Harvinder Singh
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. �
*/
 
venu gopal
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic