[java] How to write a basic swap function in Java