16

I've seen this char defined as char ch = '\117'

What kind of representation is '\117' in?

I know escaped-sequence is '\n', for instance, or unicode is `\udddd', where d is a single hex digit, but I've never seen such thing as '\117' in my entire life! Surprisingly, it does compile! (And the output is O)

user1508893
  • 8,493
  • 14
  • 42
  • 55
  • 11
    See [Escape Sequences for Character and String Literals](http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.6). – user207421 Feb 19 '13 at 05:42
  • 1
    This is octal notation. See [Why do Java octal escapes only go up to 255?](http://stackoverflow.com/q/9543026/111424), especially [rob mayoff's answer](http://stackoverflow.com/a/9543611/111424). It's probably for compatibility with older languages and programmers. – Iain Samuel McLean Elder Feb 19 '13 at 12:00

4 Answers4

11

This is the octal representation for ascii. You can see lots more values of it here: http://donsnotes.com/tech/charsets/ascii.html

Daniel Kaplan
  • 58,382
  • 45
  • 210
  • 318
8

It's in octal, a holdover from C/C++.

ldav1s
  • 15,327
  • 2
  • 51
  • 55
3

That is because its the Octal representation of captial O character.

If you try to print your char ch='\117'; , you will see that it prints O.

Rahul
  • 43,125
  • 11
  • 82
  • 101
2

It's a Octal value for character "O", when I did system.out.println(..) I got this output:

char ch = '\117';
System.out.println("Char is: " + ch);

Output:

Char is : O
Pradeep Simha
  • 17,007
  • 16
  • 53
  • 105