In Java, your variables can be divided into two categories: objects and everything else (int, long, byte, etc.).
The primitive type (int, long, etc.) contains any value that you assigned to it. An object variable, in contrast, contains a reference to an object somewhere. Therefore, if you assign one object variable to another, you copied the link, and points A and B point to the same object.
NOTE. Strings in Java are actually objects, not primitives, which are often assumed by beginners.
Hope this helps
source
share