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?

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, now I got it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.