aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes '\u000' != Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark " Watch " New topic
Author

'\u000' != " " true or false

rahul kumar
Ranch Hand

Joined: Feb 24, 2001
Posts: 75
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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Aug 13, 2001
Posts: 280
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

Joined: Jul 03, 2001
Posts: 2120
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


SCJP2. Please Indent your code using UBB Code
Bill Krieger
Ranch Hand

Joined: Sep 27, 2001
Posts: 53
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

Joined: Aug 13, 2001
Posts: 280
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

Joined: Nov 22, 2008
Posts: 18944

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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Aug 13, 2001
Posts: 280
Thanx William,
I thought the question was probably lost under the heap of new questions,and would not be answered.
Thanx for the answer.
 
 
subject: '\u000' != " " true or false