Japan's government under Emperor Meiji that came to power in 1867 was very enthusiastic about modernization, so that they could enhance their standing among the powerful western nations and show that they were not ones to be bullied like the Chinese.
The Chinese, as I mentioned, had been basically bullied by the western powers (mainly Great Britain) through several wars and unfavorable treaties. The Chinese for a long time believed they were the best nation on earth and didn't feel the need to modernize. This came back to bite them with their European adversaries crushing them in battles and taking away territory/gaining lucrative trading deals and monopolies (such as opium). Not to mention, the ruling dynasty of China during this time known as the Qing was very ineffective and gradually weakened in the later 1800s and early 1900s.
Korea had long been known as the "Hermit Kingdom" under rule of the Joseon Dynasty, and rejected contact with foreigners, hence their lack of modernization. Invasions from neighboring China and Japan only reinforced this policy.