This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
After the declaration: char c = new char; what is the value of c? 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
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:
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?
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
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.
Joined: Aug 13, 2001
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
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).]
Author and all-around good cowpoke
Joined: Mar 22, 2000
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
Joined: Aug 13, 2001
Thanx William, I thought the question was probably lost under the heap of new questions,and would not be answered. Thanx for the answer.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com