Hi Vishwas,
I've found out the reason why the char[] printing behave s differently. before going in to that let me state a few things.
----------------------------------------------------------
Here are the overloaded version of println()
method in PrintStream class
----------------------------------------------------------
voidprintln()
voidprintln(boolean x)
voidprintln(char x)
voidprintln(char[] x) voidprintln(double x)
voidprintln(float x)
voidprintln(int x)
voidprintln(long x)
voidprintln(Object x)
voidprintln(String x)
--------------------------------------------------------
Now if u go through the above list then u'll find that only char [] has got a separate println method.(There is no version of println that deals with other kinds of arrays.)
now the question arises then how are other arrays dealt with ..... And the answer is all other arrays are dealt by println(Object o) version.
Hence It's reasonalble that all arrays except char[] array may behave differently.
Ant now to the main question .. Why NullpointerException for char[].
The reason lies in the fact that the function that deals with char[] printing does not check if the char[] is null ,instead it directly access the charArray.length variable. and it gives rise to an exception if our array was null.
Now let's have a look for other arrays also. For all other arrays as I've stated earlier Object version of println is called and in this function Object.toString() function is called to get the String rep of the Object but before that it is ensured that the Object is not null and in case it is null then instead of calling toString() method a hardcoded "null" String is returned.and hence no exception.
hope this is clear now.
Thanx Vishwas for posting a good ques. I learned this because of ur ques. keep posting.
regards
deekasha