Of course, it is impossible to know for sure why countries develop differently. We cannot conduct experiments to objectively tell us why China and Japan reacted differently. We can only use informed speculation. That said, let us look at three possible reasons for this.
First, it is possible that there was simply something about Chinese culture that was less conducive to adaptation than the major aspects of Japanese culture were. Many scholars believe that culture matters very much in how countries develop and adapt to change. If they are right, it may simply be that Japan’s culture was better at adapting.
Second, we can look at the history of the two countries and the degree of internal conflict that each had. Although Japan had been united for a couple of centuries leading up to the 1850s, it had traditionally been less united than China. Perhaps this history of lack of unity made Japanese culture more accustomed to the possibility of change.
Finally, we can surmise that the relative place in the world of these two countries was responsible for the differences. China had long believed itself to be the center of the world. It was the dominant country and other countries paid tribute to it. This made it less likely to be able to conceive of the need to change. By contrast, Japan was relatively used to taking ideas from other countries and incorporating them. This was, after all, a country which had gotten much of its high culture (and even its system of writing) from China. It was accustomed to the idea that outsiders might have good ideas. This could have made it more likely to adapt to the changes brought by Western contact.
Of the three, I tend to give most credence to the last of these explanations.
The Qing government remained largely conservative and proved unwilling to adopt Western technologies and ideas, as rapidly as the Japanese state had done under the Meiji Restoration, and to adapt to changing forces in the international order in the nineteenth century. In their eyes, the West were still viewed as barbaric in nature - Chinese cultural pride was simply too deeply ingrained in Chinese society for them to stoop down to the level of the barbarians to learn from them. Such attitudes blinded many Chinese officials and prevented them from seeing the need for fundamental change in China. There was thus no significant industrialisation and the Qing authorities displayed little willingness to abandon their traditional imperial institutions, since that would only severely weaken their political power. The government in China at that time was simply too conservative and backward-looking - they only sought to retain their power and to repel the West by isolating China from foreigners. Japan, on the other hand, had always been more pliable to foreign ideas. The Meiji regime also recognised the need for Western ideas to be adopted in Japan to prevent the nation from facing the fate of colonisation. Such a recognition allowed the Japanese to be more adept at responding to the changing forces of the nineteenth century.