I am confused with null in java. Book says that if we declare a variable of reference type without initialization, the variable will have default value null. So I have a try like this
import edu.princeton.cs.algs4.*;
public class test
{
public static void main(String[] args)
{
String a;
StdOut.println(a);
}
}
However it is wrong in java because variable a isn't initialized. This contradicts to that a will have default value null.
I have another confusion is that if I run the code below
import edu.princeton.cs.algs4.*;
public class test
{
public static void main(String[] args)
{
StdOut.println(null+"a");
StdOut.println("null"+"a");
}
}
both code lines print nulla. So is it true that string "null" equals null?
Can someone help me clear these two questions? Any advice is helpful. Thx.