Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Frankie Chee
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the above:
ch\u0061r a = 'a'
a valid declaration?
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it compile?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what we were hinting, but sometimes it's better to let people find things out for themselves
Dave
 
Frankie Chee
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the 'r' stands for in ch\u0061r?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Colin Lim:
What does the 'r' stands for in ch\u0061r?

It does stand for the last character in "char".
 
Frankie Chee
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
konark gupta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya it wil run as this is the unicode for 'a'.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't fill the line with smilies. I have deleted them.

CR
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic