• 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

unicode values

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Objective46 {
public static void main (String[] args) {

char a='\u000A'; //1
char a='\u000d'; //2
char a1='\u005c'; //3
char a1='\u0027';//4
}
}

only the above four lines of Unicode values would give compile error.Is my understanding right?
The reason for asking this question is somewhere I have read that char a='\u000d';(form feed) would give compile error.But it compiled well on JDK1.4.Please clarify my doubt.
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread:


Remember, unicode escape are processed before actual compilation

This means, your source code

char c = '\u000A';
is translated to
char c = '
';

Please note - Closing quote moves to next line

// char c='\u000A';
is translated to
// char c = '
';

Please note - Closing quote and semi-colon moves to next line


char a = '\u0027';
is translated to
char a = ''';

Please note - Three single quotes - illegal

and

char a = '\u005c';
is translated to
char a = '\';

Please note - One back-slash - illegal

Same translations may break your string literals.


I used eclipse(3.1) and JDK1.4. All 4 lines have compile error.
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks wise.I have two more doubt on this.

1) char a4='\0'; //legal

Like the above one,\1,\2,\3,\4,\5,\6,\7 are compiling fine. But \8,\9 are giving error. Again \10 is compiling fine.

2) Likewise,octal numbers

char c9 = '\020'; //legal
char g8='\0155'; //illegal

In both cases, I am looking for the rule behind those,please.
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone please clear my doubt?
Shiva.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'\ddd' is for octal character literal. you can not have 8 and 9 in octal number.

char a ='\8'; //should be '\10'
char b ='\9'; //should be '\11'



the character literal for octal number is in the range '\000' to '\377'
char g8='\0155'; should be '\155'
[ October 02, 2006: Message edited by: wise owen ]
reply
    Bookmark Topic Watch Topic
  • New Topic