The experiences of these two countries were quite different in that China was exploited to a much greater degree than Japan was. Japan learned more from the West whereas China was simply used.
The Chinese had more that the West wanted and remained arrogant towards the West for longer. Because China was a bigger market, the West was more eager to exploit it as in the Opium Wars. Because it was more arrogant (having been the dominant power in its region for centuries), it did not learn from the West.
By contrast, Japan was (eventually) eager to learn from the West. Once it was "opened" by Perry, its leaders saw the need to emulate the West. For this reason it started to copy Western ways and soon became the most powerful country in Asia.