• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

'\u000' != " " true or false

 
rahul kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After the declaration:
char[] c = new char[100];
what is the value of c[50]?
a) 50
b) 49
c) '\u0000'
d) '\u0020'
e) " "
f) cannot be determined
g) always null until a value is assigned
whats the ans and,is '\u000' and (e) option different
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays of primitives are initialized to zero - in this case you would represent this as '\u0000'
Answer e seems to involve a String with a single space character which is '\u0020'.
Bill
------------------
author of:
 
leena rane
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even i would have selected c as the answer.
A qn. in Philip Heller notes says:
What are the default initialization for an array of type char?
Answer:'\u0000'(the null character)
I am a little confused with the content in bracket.
Can somebody make it clear-are null character and null literal different?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
null in Java code is a literal that can only be assigned to a reference type variable
'\u0000' is, as any char literal, assignable only to some primitives type variables.
because the array is of type char, the default value is char, not a reference type
 
Bill Krieger
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by leena rane:
Answer:'\u0000'(the null character)
Can somebody make it clear-are null character and null literal different?

The null character and null literal are different. This use of the word null ("null character") is not a part of Java. It is a shorthand way of describing a particular value that is commonly used by C, C++, ex-C and ex-C++ programmers and has nothing to do with the Java keyword "null." Using the word null this way only serves to confuse programmers who are not experienced C programmers.
 
leena rane
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Jose,
Thanx Bill,
if question comes:
null is default initialization value for an array of
type char
o true
o false
what should i select??
I was told by a senior programmer recently to select true for this question(I was very surprised ),
i am not satisfied with this answer.
Thanx in advance
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please correct me if I am wrong or add more stuff.
thanks
Chandrashekar!
[This message has been edited by chandrashekar munukutla (edited October 03, 2001).]
[This message has been edited by chandrashekar munukutla (edited October 03, 2001).]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if question comes:
null is default initialization value for an array of
type char
o true
o false
what should i select??
I was told by a senior programmer recently to select true for this question(I was very surprised ),
i am not satisfied with this answer.
-- Your senior programmer must normally use C or C++ where null is not so rigidly defined.
As others have pointed out, in Java null has meaning only with reference variables so I would choose false, but that assumes the question was about values in an array that has been created.
Of course, there is always the sneaky interpretation that the default for any reference, including an array is null, so the question is open to interpretation.
char[] c ; // instance variable would have null
Bill
 
leena rane
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx William,
I thought the question was probably lost under the heap of new questions,and would not be answered.
Thanx for the answer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic