• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

char literals

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class MCZ24 {
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);
}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. 5
f. None of the above


Answer: f (None of the above)
Reason given :
All of the declarations are legal. The first three ( 061, '\61', '\061' ) are declared in octal format. The fourth (0x0031) is declared as a hexadecimal literal. The fifth ('\u0031') is a Unicode escape sequence.

061 is a valid char literal.Its in octal format.
But is '\061' and '\61' in octal format?
Can anyone justify how '\61','\061' are valid char literals.

What are the various Unicode escape sequences ?

Thanks in advance,

regards,
rajani.
 
Rajani Sudhakar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the various unicode characters,escape sequences or backspace characters etc.... which are required to know for the Programmer's exam?

Thanks in advance,

regards,
rajani.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajani,

According to JLS one of the Escape sequence type are using octal literals.

There are three formats of Octal Escape sequences.

1) \octaldigit
2) \octaldigit octaldigit
3) \zerotothree octaldigit octaldigit

For more information on EscapeSequence refer JLS @ http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101089

By the way I dont know how much we need to cover for SCJP 1.4

Regards
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Both \61 \061 are in octal and they are within the range of 0 to 2**(16-1). So, they should be valid.

Originally posted by rajani sudhakar:
class MCZ24 {
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);
}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. 5
f. None of the above


Answer: f (None of the above)
Reason given :
All of the declarations are legal. The first three ( 061, '\61', '\061' ) are declared in octal format. The fourth (0x0031) is declared as a hexadecimal literal. The fifth ('\u0031') is a Unicode escape sequence.

061 is a valid char literal.Its in octal format.
But is '\061' and '\61' in octal format?
Can anyone justify how '\61','\061' are valid char literals.

What are the various Unicode escape sequences ?

Thanks in advance,

regards,
rajani.

 
Rajani Sudhakar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou Anuradha... for sending me the link..

regards,
rajani.
 
reply
    Bookmark Topic Watch Topic
  • New Topic