I understand that trying to compare the value of an Object that's null with something will result in a NullPointerException, e.g.,
String bob;
if(bob.equals("blahblahblah")){do_something();}
and that it's a good idea to use nested checks like so:
if(!bob.equals(null)){
if bob.equals("blah blah blah"){
do_something();
}
}
But if I haven't given bob any value yet, I get an error when I run the above saying bob hasn't been initialized - since I'm comparing bob to null, I should be able to run this without a problem, shouldn't I?
Thanks.
null: stackoverflow.com/questions/218384/…falsefor boolean,0for numeric values,nullfor references). If variable will not be initialized and tried to use, code will not compile. BTW only class fields are set up by compiler to have default value, local variables (the ones declared in method need to be initialized by user/programmer).int i; /*some time passes*/ i=42;In this case memory foribeforei=42could in fact not reset, so it can be any set of bits, but we can't check it because Java explicitly demands to initialize it before it can be used (as jls-4.12.5 describes).