Skip to content
Advertisement

What is the difference between Address and Reference in Java?

First of all, I know that Java is call by value.

However, in a certain article, there is no such thing as an address in Java, and you should use the word reference. In my opinion, both words are interpreted with the same meaning. Am I wrong?

  1. What is the difference between address and reference, and do you have such a strict definition that you have to distinguish between the two?

  2. Some people use the term memory reference. Is this the address then? Or is it a reference?

I’ve searched on various sites, but I can’t find an article that can answer my question, so I’m posting this question. thank you.

Advertisement

Answer

Java spec doesn’t introduce definition of address, so if we not talking about JVM implementation there is no such thing.

If we look deeper we can say that difference between address and reference is caused by GC. Specifically by its ability to relocate objects.

Lets say we have object o in memory. Its address is 100500. After GC all references pointing to o will still point to it, but 100500 is not where that object is located now.

This is only my opinion. There is, as I said before, no official definition of address.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement