It will print out XXX and YYY because you have initialized J1 and J2 to that. You don't actually swap them to the value you want them to hold.
As tfityo said, reference is a way, or a pointer. I would use a pointer really. You point one variable to a new variable that u can use outside of the scope, brilliant stuff who ever came up with that :P