Why was China, a country with a gigantic population and ancient traditions, militarily inferior not only to the leading European

Why was China, a country with a gigantic population and ancient traditions, militarily inferior not only to the leading European powers, but also to small (in comparison) Japan?

China was often subjected to external attacks by other states, which almost always gained upward, internal strife and gravdan wars greatly hampered state progress. much later, good trade relations with Europe were established.
Japan is an island state, and no one could ever completely capture it. Therefore, she has always remained independent.

Remember: The process of learning a person lasts a lifetime. The value of the same knowledge for different people may be different, it is determined by their individual characteristics and needs. Therefore, knowledge is always needed at any age and position.