Japan is essentially unique in world history as being both the only country to eliminate modern weapons during the two hundred and fifty years of isolation under the Tokugawa shogunate but also, quite famously, remaining closed to the world throughout most of this period. With few exceptions, Japanese who travelled abroad did so under an effective death sentence on return and foreigners were strictly limited to Dejima, a small trading island off the coast of Nagasaki, some 1,000 kilometres from Tokyo.
And then in 1853 Commodore Matthew Perry arrived in a steam-powered gunship and offered the government a year to think about opening trade routes with America and the rest of the world or he would open the routes for them. Anchoring first at modern day Yokosuka, now a US Naval base (from where the phrase "Hunky Dory" reputedly derives from) at the mouth of Tokyo Bay. In 1854 he sailed closer to within sight of Tokyo and set down at Yokohama, then a small fishing village.
The government, seeing the options of having Tokyo shelled from the sea and all inbound shipping blown out of the water or acquiescing to the request, signed the agreement and Japan was an open country. In 1854 two new ports were opened to foreign shipping, one being Hakodate and the other generally being thought to be Yokohama. But the second port was actually Shimoda, at the far end of the Izu Peninsular. Out of sight, out of mind was the policy of the government of the day. Until they realised the foreigners were counting all the trade ships running the routes to Tokyo. And then they relocated them quickly to Yokohama. Better the devil you know as it were.