• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

representation

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does this ('\141' )representation mean
aval = '\141';
System.out.println(" val of a : " + aval);
we get " val of a : " a
'\141' is a...
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is the octal representation of a character. For a hexadecimal representation use '\u0141'
The output will be different in each case
[This message has been edited by Saritha Pilla (edited March 07, 2000).]
[This message has been edited by Saritha Pilla (edited March 07, 2000).]
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And one more point regarding this.
The octal escape representaton of a char has the foll. format
'\digit1 digit2 digit3' //here digit1 can be '\[0-3]', digit2 and digit3 can be '\[0-7]'
'\digit1 digit2' //here digit1 and digit2 BOTH can be '\[0-7]'
'\digit1' //here digit1 can be '\[0-7]'
Eg.
char c1 = '\377'; //ok
char c2 = '\477'; // NOT ok
char c3 = '\77'; //ok
char c1 = '\7'; //ok
regds
maha anna

[This message has been edited by maha anna (edited March 07, 2000).]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saritha,
octal representation starts with 0 right?, how come '141' is octal.?, can you please share your thought.
Related question, if there is int like 6, how do you write in hexadecimal form, my answer is 0x0006. Is it correct.
Thanks
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

> aval = '\141';
just think of it this way:
octal 141 -> decimal 97 -> ascii code for 'a'


 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference is 0141 is an octal representation of a number. But '\141' is the octal escape sequence representation.
char c1 = 0141;
char c2= '\141'; BOTH staments represent the SAME char of decimal value 97
I hope this helps.
regds
maha anna.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[ ignore this post, it's incorrect - I'd delete it, but then maha anna's post wouldn't make sense. - Jim ]
The octal and hex escape sequences are for use inside single or double quotes, to represent an individual character. Outside of quotes, they don't work.
[This message has been edited by Jim Yingst (edited March 07, 2000).]
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim,
This code seems to work and creates a dir structure ./ABC/DEF
when you compile with these options "javac -d . test.java".
If I understand you correctly, do you mean to say the foll. code is not a valid code ?
regds
maha anna

 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm...
Yes, that is what I meant. Evidently I was wrong. Oops - thanks m.a.!
 
Grow a forest with seedballs and this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic