They both used to be something like vassal states to China when China was at the peak of its imperial power. There were constant wars for independence as well as for Korea that involved Japan who often went on the offensive and they would often be beaten which only reinforced their vassal position. China influenced them both in such a way, mostly culturally.