File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes char Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "char" Watch "char" New topic


Priya Rajan

Joined: Jul 06, 2001
Posts: 27
char c='\101';//there is no u after slash
what does it mean?
I think Characters can only be represented with hexadecimal numbers using \u. Am I right?
ex: char c='\u0000';
Pl explain
tvs sundaram
Ranch Hand

Joined: Jan 28, 2001
Posts: 153
Hi Priya,
Char literals are single quoted characters or unicode values (begin with \u).
Priya Rajan

Joined: Jul 06, 2001
Posts: 27

Pl explain why this line is compiled? It is neither char nor unicode.
char c='\101'; //it prints some char also when printed.
I have exam tomorrow. Pl help
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Wow - that is interesting. The '\101' seems to be interpreted as octal, resulting in 65 decimal = 'A'
It is actually in the Java Language Specification 3.10.4 but I never came across it before. Literal char examples given in the JLS are:
'\t' escaped tab char
'\\' escaped \ char
'\u03ad' unicode - interpret as Hex
'\uFFFF' unicode
'177' octal
plus a couple of examples with non-ascii characters.
[This message has been edited by William Brogden (edited July 29, 2001).]
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1183
According to William´┐Żs book, \xxx is a valid escape sequence.
It says in page 34, \xxx is a character in octal representation; xxx must range between 000 and 377.

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
I agree. Here's the link:
subject: char
It's not a secret anymore!