File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

?a?

 
Hemant Patel
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys
I gave exam in JohnJuntMockExam
There is one question
Q-8 :
which of these is the correct format to use to create the literal char value a?
(1) ?a?
(2) "a"
(3) new Character(a)
(4) \000a
Ans is (1)
I gave ans (3) but it is wrong
I can't understand why it is ?a?
Himanshu Amin
------------------
"JAVA BANAYE BAVA"
 
Chris Cingrani
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, I have never seen ?a? before. However, I found this on page 570 of Mughal and Rasmussen's "A Programmer's Guide to Java Certification":
"Not all Unicode characters can be represented in other encoding schemes. In that case, the '?' character is usually used to denote any such character in the resulting output, during translation from Unicode."
Could this be what is going on in your example?
Anyone have any ideas?
Chris
[This message has been edited by Chris Cingrani (edited January 09, 2001).]
 
Maitham H
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand this!!!
what in the world is ?a?
I've tried it in a small class, with the code
char c = ?a?;
but, as i excpected, i get compile error.
is the way I used this strang ?a? correct?
anyone can give more professional help on this?
 
bill bozeman
Ranch Hand
Posts: 1070
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question really states:
1. 'a'
Bill
 
Bin Wu
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also confused why it is not answer c. I suppose if it because new Character( a ) creates the reference but the literal value. Am I right? Besides, my question is: When I should use primitive type and when reference to char,int and others? Thanks.
 
bill bozeman
Ranch Hand
Posts: 1070
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 3 doesn't create a literal char 'a' it creates a wrapper class for char 'a'. This create a Character object, not a char primitive.
Bill
 
Bin Wu
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question remains when i should create a wrapper class and when primitive. Similar question about other primitive type.
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic