Java tree work