Angela : "....null is an reserved literal.which is the default value for Strings and boolean ..."
Gagan : No , Angela , null is a special literal , agree , but it is not default value for boolean ? It is default value for object references which are not local ( class members and object members )
Angela : "....whether null is taken as an object or string...."
Gagan : String is a Object itself ,not primitive type , and
null is considered of no-specific-type itself ( it is not a Object of any Class , tho can be casted to any Class Type )
if( s.equals(null) ) //1 exception Okay , fine here we are passing a
null to a method which expects a Object , so we get a nullpointer exception at runtime.
if( s.equals("null") //2 exception "null" is NOT same as
null , "null" is a valid String , whose value is String "null"
String s1=null; // string-reference s1 is null
String s2="null"; // string-reference s2 points to a string-object which contain string "null"
String s3="Java"; // string-reference s3 is points to a string-object which contains string "Java"
if ( s == null ) //3 works out fine Of Course , here we are comparing string-reference s , with literal
null , which happen to be the value of reference s , so it returns true
Here is wht API-Doc say for String.equals()
Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
Good Luck !
------------------
Gagan (/^_^\)