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?
Asked
Active
Viewed 100 times
1 Answers
0
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.

Ctznkane525
- 7,297
- 3
- 16
- 40
-
Thanks, now I got it. – Lavlesh Mishra Jan 03 '18 at 14:58