• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Unicode in chars

 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I am trying to compile the following code I am getting compile time errors for \u0010, \u0020 and \u0040. How ever \u0030 is fine. Can any one give any reason for this behaviour?
I agree that first 32 chars are non printable. But why the comiler is rejecting 0040 and accepting 0030?
If I give the same numbers with single quotes around every thing is fine.
public class A {
public static void main (String [] args) {
char c = \u0010;
char c1 = \u0020;
char c2 = \u0030;
char c3 = \u0040;
System.out.println(c);
}
}
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
char variables can be assigned a character within single quotes. No quotes in the examples and the compiler complains.
It is possible also assign a constant integer that is in the range of the values accepted by the type char.
char i = \u0030 is the same as
char i = 0
and thus it is ok
[ January 23, 2003: Message edited by: Jose Botella ]
 
Sarma Lolla
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jose Botella ,
Thanks for your explanation. It cleared my mind.
 
Yeah, but is it art? What do you think tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic