Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic