Why was China so devastated by colonization whereas Japan was never colonized (or at least to the extent China was)?
There's a lot of scholarship on this topic by Chinese academics themselves. The consensus is that Japanese had the benefit of strong leadership who were willing to put in the work for reform.
The Chinese senior leadership was divided on reform. After defeats in the second Opium War, China engaged in modernization by purchasing modern weapons, ships, and building arsenals. By the time of late Qing after defeat by Japan, I would argue that many if not most of the politicians knew that China was backward and something needed to be done. Many people thought the superficial modernization of prior years was only treating the symptoms, not the cause. Many even looked to the Japanese experience of modernization of the political system and the underlying aspect of the society. However, the conservative factions were afraid of losing their status over political reform.
In fact, the Guangxu emperor himself was a proponent of reform and modernization. His retainers and advisers included famous constitutionalists like Kang Yu-wei and Liang Chi-chao. They led arguably the most famous and quintessential movement, called Hundred Days' Reform. This ended in a coup by the conservatives faction led by Empress Dowager Tzu-hsi.
This is demonstrative of the problem that plagued China. The reform minded politicians had the drive, but they did not have the power security to push through such changes.
First of all, China was never colonized. Western powers had "spheres of influence," there were a few small Western enclaves along the coast, and Westerners enjoyed territoriality, but China as a whole was treated as a sovereign nation (unlike India, which was completely taken over by the British).
That being said, this question can be better answered if it were divided into two sections. The first would be to look at the reasons why Japan was successful, in this regard what /u/JillyPolla said is correct, the Japanese had strong leadership who were united behind the banner of modernization. Another possible reason is that Japan already had experience with "modernization". In the 7th century, the Japanese launched the Taika Reforms which aimed to create a state modeled after Tang China. In the subsequent two centuries, the Japanese sent many missions to study in China and imported vast amounts of knowledge. There has been a lot of scholarship comparing the Taika Reforms to the Meiji Restoration, but I'm not sure if a direct correlation exists between the two (in other words - whether or not this first experience made the second experience easier), hopefully a Japan expert can answer that.
As for why the Chinese failed. I think there are three main reasons. First and foremost was that modernization was decentralized. It was done mostly on a provincial level by powerful regional viceroys like Zeng Guofan, Li Hongzhang, Zhang Zhidong, but national policy as a whole was very ambiguous. The Qing government did launch "self-strengthening movements" to modernize the military, build telegraph systems, and lay out railroads, but the central government usually deferred these projects to provincial authorities. As Jonathan Spence wrote in A Search for Modern China:
These policies had the general support of the central government in Peking, but since revenues were short and many problems clamored for attention, Zeng and his colleagues in the provinces were left a free hand.
The reform movement of 1898 was an attempt to centralize reform and establish a national policy. A very common misconception with the 1898 reform was that Cixi was against it and ended it. As I pointed out here, this is actually false. Cixi supported the reforms, but she was against its radicalism. This leads me to my second point - the Chinese reform failed because Kang Youwei and his reform clique was too radical in their thinking and too zealous in their attempt. They wanted to create a strong constitutional monarchy similar to Germany and Japan, and they believed that the Guangxu emperor should hold power, rather than Cixi. So rather than go to the person with the most power, they instead decided to remove Cixi from the scene altogether, an action which ultimately lead to their failure.
The third reason was that China never embraced reform the same way Japan did. The Meiji government abolished the old feudal system/stratified society and built a constitutional democracy where it was easier for men of talent to become employed by the government. Chinese reforms was based on a very conservative approach of "Chinese learning for the fundamental principles, Western learning for the practical uses" (中學為體,西學為用). The Chinese only modernized on the surface - building factories, railroads, creating new military forces - but the core was still an old system centered around an absolute monarch. In comparing Li Hongzhang and Ito Hirobumi, Liang Qichao heavily criticized the Qing's absolutism as the major reason why Ito was more successful than Li.