When you declare a variable inside a method without assigning a value, Java refuses to compile if you try to use it. Local variables have no default.
int x;
System.out.println(x); // compile error
But class-level fields (declared outside methods) get automatic defaults:
int,short,byte,longdefault to0floatanddoubledefault to0.0booleandefaults tofalsechardefaults to'\u0000'(the null character)- Reference types (like
String) default tonull
Relying on defaults is risky. null causes NullPointerException the moment you call a method on it. Assign values explicitly. Your future self will thank you when debugging at midnight.