• 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

char range

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
Though this question is very fundamental, still i want to have a clear view regarding this:::
char c1 = 'a'; //valid
char c2 = 65; //valid
char c3 = '\u00000d'; //valid
Now pls tell me what are the ranges in all the cases ie
for c1 --- the range could be a - z and A - Z
for c2 --- ???
for c3 --- ???
coz i always make mistake in c3 case.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Mona,
The range for char is from 0 - 65535. For 'c1', a-z and A-Z are mere representation of ASCII values. And for c2 its the normal range(you can also put some octal and hex numbers in it) and as for c3 its the unicode representation of the hex numbers. so anything in the range of 0-65535(decimal integer) is acceptable here(Even ASCII, but i dont how it looks like ).
I hope this explains you in a better way.
Kind regards,
Anish Doshi.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I too have the same doubt regarding c1,c2,c3.c1 and c2 is fine, I could understand from the reply.How about c3, you said its unicode repreasentation of hex, does that mean u stands for unicode representation and d for decimal then the number is 0 .Am I right .
Regards,
Kirti
[ November 27, 2003: Message edited by: kirti ragannagari ]
 
Anish Doshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey agn.
Not exactly Mona.
Do you know what exactly a hexadecimal no. is? if no, then I think you got to a brush on it a lil bit. and yes then the d does not represent a decimal but its no in whole(00000d) which means 13. And as for unicode, 'u' after the escape character(\) mean its a unicode character. If you wanna know about unicode u can reach Unicode web page but If you can understand a single part of it, you are a real pro. .Bur yeah u got to know wat unicode and hex nos. are.
If in doubt agn. you can ask agn. lolz.
Kind Regards,
Anish Doshi.
 
Anish Doshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to add that the unicode nos are always hex values.
[ November 27, 2003: Message edited by: Anish Doshi ]
 
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

char c3 = '\u00000d'; //valid


This is invalid. The unicode representation should be '\uXXXX' where the four Xs is hexadecimal form. While '\u000a' and '\000d' are valid hex form using it in java will result in compile-time error. These are newline and carraige return respectively and interpreted by the compiler as line terminator characters.
Different ways for char assignment:
char t = 'a';
ch\0061r t = 'a';
char t = '\0061';
char \u0062 = 'b';
char t = '\n'; // newline
char s = 65;
char m = '\333';
// --> last the last three digits is an octal value which can only be less than 377 (equivalent to first 256 characters including 0).
 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
correction above:
char t = '\u0061'
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I like to understand this better too.
c1 and c2 should be OK with me. However, for c3, just like Mona, I always get confused!
However, I read somewhere (or while doing some mock exam) that newline or carriage return are invalid character for c3. Am I right? Could someone pls explain this to me. Thanks.
If there is any invalid value for c1, c2 or c3, could you please list out only thouse invalid values for me? Thanks.
CH
 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
1. hex form (unicode)
Minimum: \u0000(0 in decimal)
Maximum: \uFFFF(65535 in decimal)
** last four digits is hex
** cannot use '\u000a' and '\u000d'
2. octal form (escape sequence)
Minimum: \0 (0 in decimal)
Maximum: \377 (255 in decimal)
** last three digits is octal and should not be more than 377 (octal)
Other escape sequence:
'\n' - new line
'\t' - tab
... (these 2 are all i know)
3. numeric
Minimum: 0
Maximum: 65535
4. character
e.g.
'a', 'b', 'A', etc...

Pls. include those i've missed...
 
CH Lee
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found what the illegal unicode character for c3.
http://www.javaranch.com/certfaq.jsp --> see "char a = '\u000A'. Why is this invalid?"
Hopefully there won't be such tricky question in the real exam.
CH
 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'\u000a' and '\000d' are newline and carraige return and interpreted by the compiler as line terminator characters. So you cannot use these two.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic