thoroughly fixed java query