Q:

How come printing a string(an Object) in java prints it?

When we do:
String string = new String("Ralph");
//This creates a reference called string that points to a sequence of 
//characters in memory

This is the same as:
String string = "Ralph"; 

When we print both, we get the actual value of the string.
If we print any other object in Java, we get an address for that object.
My question is, is there any dereferencing that is taking place behind the scenes?

A:

When you pass an object reference to the System.out.println() method, for
example, the object's toString() method is called, and the returned value of toString() is shown in the following example:
public class HardToRead {
    public static void main (String [] args) {
        HardToRead h = new HardToRead();
        System.out.println(h);
    }
}

Running the HardToRead class gives us the lovely and meaningful,
% java HardToRead
HardToRead@a47e0
Now,
Trying to read this output might motivate you to override the toString()
method in your classes, for example,
public class BobTest {
    public static void main (String[] args) {
        Bob f = new Bob("GoBobGo", 19);
        System.out.println(f);
    }
}

class Bob {
    int shoeSize;
    String nickName;
    Bob(String nickName, int shoeSize) {
        this.shoeSize = shoeSize;
        this.nickName = nickName;
    }
    public String toString() {
        return ("I am a Bob, but you can call me " + nickName +". My shoe size is " + shoeSize);
    }
}

This ought to be a bit more readable:
% java BobTest
I am a Bob, but you can call me GoBobGo. My shoe size is 19

