When we declare a string as String str = null, what really happens? Is it only declaration or because assignment is done so it is declaration with initialization?
1 Answer
In Java you have two types of data types: Value types and reference types.
Value types point to a location in memory with the data. For example, int, char, etc. They cannot be null.
Reference types on the other hand, have a pointer to the location of the data. A null string means the reference doesn't point anywhere, meaning the data doesn't exist. This is fundamentally different than an empty string.
1 Comment
Lavlesh Mishra
Thanks, now I got it.