File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Is ch\u0061 a='a' a valid declaration? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is ch\u0061 a= Watch "Is ch\u0061 a= New topic
Author

Is ch\u0061 a='a' a valid declaration?

Frankie Chee
Ranch Hand

Joined: Oct 26, 2003
Posts: 43
Why is the above:
ch\u0061r a = 'a'
a valid declaration?
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Does it compile?


Please ignore post, I have no idea what I am talking about.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

as a follow on to Willaims question, based on compiling the example you gave, why is there a difference if you change ch\u0061r to ch\u0062r?
I haven't tried this myself, but it might give you a hint as to what is going on...
(OK, i tried it to make sure it gives the output I expected using eclipse)
Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
the above declaration
ch\u0061r a='a';
is perfectly legal. this is because \u0061 is treated as a by the java compiler and therefore it becomes
char a='a';
hope this helps


Thanks,
Shekar
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

That's what we were hinting, but sometimes it's better to let people find things out for themselves
Dave
Frankie Chee
Ranch Hand

Joined: Oct 26, 2003
Posts: 43
What does the 'r' stands for in ch\u0061r?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Colin Lim:
What does the 'r' stands for in ch\u0061r?

It does stand for the last character in "char".


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Frankie Chee
Ranch Hand

Joined: Oct 26, 2003
Posts: 43
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

konark gupta
Greenhorn

Joined: May 20, 2010
Posts: 1
ya it wil run as this is the unicode for 'a'.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

konark gupta, welcome to JavaRanch.

Please note that you replied to a topic from November 2003. I don't think that the original poster is still waiting for an answer six and a half years later (and the question was already answered).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40061
    
  28
Please don't fill the line with smilies. I have deleted them.

CR
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is ch\u0061 a='a' a valid declaration?