Java Data Type Default Values

When a field is declared, It's not always necessary to assign a value. Fields that are declared but not initialized will be set to a reasonable default by the compiler. This default will be zero or null, depending on the data type.

The following are the default values for the above data types:


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.


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)