Could anyone provide simple example when and where to declare null or 0 or "" while declaring variables in java? I went through some examples but didn't understand, so can anyone explain clearly with some simple examples?
false/null/0 (it will be redundant):
Each class variable, instance variable, or array component is initialized with a default value when it is created (§15.9, §15.10):
Local variables are slightly different; the compiler never assigns a default value to an uninitialized local variable. If you cannot initialize your local variable where it is declared, make sure to assign it a value before you attempt to use it. Accessing an uninitialized local variable will result in a compile-time error.
String myStr = "";If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With