reference in Java

Non-primitive data types are called reference types because they refer to objects. In Java, all objects are accessed by reference,
A value is assigned to a reference in one of two ways: 
* A reference can be assigned to another object of the same type.
* A reference can be assigned to a new object using the new keyword. 

The default value of a reference is null.
In Java, you never have direct access to the memory of the object itself. Conceptually, though, you should consider the object as the entity that exists in memory, allocated by the Java runtime environment. Regardless of the type of the reference that you have for the object in memory, the object itself doesn’t change. For example, since all objects inherit java.lang.Object, they can all be reassigned to java.lang.Object.
* The type of the object determines which properties exist within the object in memory.
* The type of the reference to the object determines which methods and variables are accessible to the Java program.

If a reference is set to null, the object is eligible to garbage collection.
```
public class Main {
    public static void main(String[] args) {
        String s1 = "abc";
        String s2 = "efg";
        s1 = s2; // now can garbage collect "abc"
        s2 = null; // cannot garbage collect "efg", cause s1 point to it
        s1 = null; // can garbage collect "efg"
    }
}
```