In the language specification it says:
local variables are definitely set before use. While all other variables are automatically initialized to a default value, the Java programming language does not automatically initialize local variables in order to avoid masking programming errors.
What is exactly masking programming errors are in Java?
An example explaining this, would be nice.
Thanks
To understand this, you need to compare with what C/C++ do. In C/C++, a local variable contains garbage value when declared. So, if you forget to assign a value, the compiler won’t complain and all references to such a local variable will work with the garbage value, resulting in unexpected behavior.
In Java, such an uninitialized local variable results in a compile-time error making the developer explicitly initialize it to a meaningful default value before using it.
C/C++
The above snippet is valid in C++, but invalid in java.