0

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 Answers1

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