Java Solution