Mostly using arrows not swords. But yumi is inferior weapon compared to reflexive bow used by Chinese, Korean, Mongol or Turkic soldiers.
Also if you look at any Japanese castle (Himeji had been well preserved by US Bomber Command for navigational purposes) you will quickly realize that any continental army will take at most a week to dry it's moats and dig mines under it's wall. Fortunately Japan never had seen invading army on its soil.
[1] https://en.m.wikipedia.org/wiki/Yumi
[2] https://en.m.wikipedia.org/wiki/Composite_bow
This samurai / bushido hype is so much out of proportion and simply untrue.
While in the same time real history of Asia is full of military class of exceptional value. Indian Rajput, Islamic Gunpowder Empires, Malays, Mongols - to name just a few
https://en.m.wikipedia.org/wiki/Gunpowder_Empires
https://en.m.wikipedia.org/wiki/Rajput
https://en.m.wikipedia.org/wiki/Malacca_Sultanate
https://en.m.wikipedia.org/wiki/Qing_dynasty
https://en.m.wikipedia.org/wiki/Hwarang