Indeed in the first half of the 19th century, Japan was fairly isolated, only the port of Nagasaki and the small island of Dejima were opened to western traders. However, Japan was definitely not an "antiquated nation" at this time, it was probably with the Ottoman empire the most advanced non western/european nation of the world.
It had a an efficient administration and economy, the agriculture had impressive yieldings allowing Japan to sustain 30 millions inhabitants by 1800 (as much as France and slightly less than Russia!). Japan had also a relatively high literacy rate, a decent rate of urbanization and although the country was isolated, they did follow western science advancement via the port of Nagasaki, where among other things, students followed course given by western teachers. There is a concept/word Rangaku (literally "dutch learning") designated the process of the Japanese getting knowledge (This included medicine ,astronomy, mechanic, chemistry and even weapon productions, the Portuguese taught the Japanese how to build modern weapons) from the Dutch and European more generally from the middle of the 17th century to the effective modernization of Japan.
In 1853 with admiral Perry's military expedition with steamships in Japon forced the country to sign the convention of Kanagawa that opened trade and diplomatic relations with the USA, similar treaties were signed with other western countries soon after, putting an end to centuries of isolation.
But let's go back to our topic, why did Japan was able to modernize so quickly? The notion of modernization speed is inherently relative to the one of other Asian countries and especially the giant of Asia, China. In other words why did Japan successfully westernize and not other countries? As always there are multiple factors that explain this:
-The strength of the government: in China, the loss after the 1st war of Opium in 1842 led to a limited modernization but also severely weakened the imperial authority, leading to one of the most deadly revolt in the history, the Taiping rebellion which lasted 13 years, saw a temporary independent kingdom in southern China and caused the death of 20-30 million people. No need to say that the imperial Chinese Qing dynasty suffered a lot and was even more humiliated as western countries help was required to crush the rebellion! In fact China would face a century of internal troubles and wars with an obvious collapse of the central authority. On the contrary in Japan the unequal treaties reinforced the imperial authority as the Shogun took the blame of the humiliation, a few decades latter reformers joined the emperor to overthrow the Shogun and the civil war (called war of Boshin) only lasted for one year and a half. Even if 8 years latter there was another revolt, the Satsuma revolt led by some reactionaries samurai opposed to Japan modernization, those crisis were no where as big as the troubles China faced. This allowed the emperor to virtually suppress all the internal opposition. The title of samurai was abolished but far from being wiped they became the core of the Japanese modern administration and economy: instead of being warriors and land owners they became (high) civil servant, businessmen and of course military officers. Because the state was strong it was able to collect taxes efficiently led drastic reforms like reducing nobility privileges, applying land and land taxes reforms, instituting a national conscription system and investing money in education, industrialization or a modern army.
-Timing and geopolitical considerations. China was richer, it had a huge commercial surplus (due to tea trade and also to a lesser extent textile, chinaware and silk) with western countries which urged the British to take measures to balance trade. Unlike Japan which was only seen as an insignificant threat, in fact Japan was even used by the west against China. Also the American civil war latter protected Japan from an intervention which gave Japan a precious respite so that Japan was able to watch and learn from China's defeats. Latter the British wanted a strong Japan to fight the Russians and limit their expansion in Asia, in 1905 they pressured France not to help Russia against Japan for example.
-As stated before, Japan has a long tradition of learning from the west, after the Meiji Restoration, Japan sent students to learn abroad while they massively received advisors and heavily relied on their expertise. Japan took a bit of each European countries: the laws were based on a mixed of Napoleonic code and Germanic law. The Meiji constitution was inspired by the British political model, for instance they kept the 2 house system. The founder of the imperial navy, Enomoto Takeaki learnt about the naval warfare with the dutch and latter would take inspiration of the Royal Navy to build the Japanese navy, while also taking a bit inspiration of the French Jeune Ecole. Last but not least their army organization was inspired by the german großer Generalstab; this also includes their relative independence toward the political power (and it will be one of Japan militarism in WW2 after the destruction of the civil political power)
I recommend reading this excellent answer by /u/t-o-k-u-m-e-i to a similar question: How did Japan industrialize so quickly and so successfully? The answer covers a wide range of factors within a well-presented timeline.