Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

char literal

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my question
class test {
public static void main (String[] args) {
char a = 061; // 1
char b = '\377'; // 2
System.out.print(""+a+b);
}}

this compiled fine but i will declar like that char b = '\378' it would not compile.

char b='\0' to char b='\377' this range work fine but after '\377' is not compile, Any body know help me
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value 378 is invalid when you are using the octal base. You can only have digits 0 through 7.
 
venkataraman muthuvel
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Chris Allen

Thanks for ur help

bye
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must reffer the JLS It clearly says that after \ you can have a maximum of 3 digits (all octal) the first digit can be only 0,1,2,3. So the maximum number possible is 377. Anything more than that is not possible. 377 is equivalent to 255 in decimal. only \u0000 to \u00FF is possible as octal.

Sanyev

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.)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic