Java example of writing object to file