can the Japanese legally build an offensive military force to counter those threats?
No. But it's trivially easy to build a large defensive force to protect yourself, your friends and your interests, even if it far away from your home territory.
(For example, the US has the Department of Defense and yet regularly invades other countries with the justification of defensing US interests.)