for a long time looking up to the empires of the mainland. In the 19th century both had enlightened monarchs (Queen Victoria and Emperor Meiji) who ruled a very long time and took their countries to their heights.
Perry ExpeditionIn 19th century, Japan was under feudal lords with only a nominal power with the emperor. It was a very closed and stagnant society. This changed in 1854 when an American named Matthew C. Perry was dispatched by President Fillmore to force the opening up of Japan. There was both a religious missionary motivation as well as business motivation. US and China had a very booming trade capitalizing on China's fall and US wanted to extend that to Japan too. Perry Expedition and Gunboat diplomacy. With warships threatening Edo (Tokyo), the local chief Abe Masahiro had to give in and open trade with the west.
Like in China and India, the trade with the west didn't go well for the Asian country as it was not in their terms. It was disastrous and shred the Japanese economy to pieces. To make matters worse there were massive earthquakes that shook Japan - in a physical as well as a metaphorical way. Ansei great earthquakes
Within a decade the Shogunate [rule of feudal lords] came to a dramatic end through public anger. The teenage emperor called Emperor Meiji took up the throne after his father was poisoned. In that time, the emperor formally ruled from Kyoto, although the real powers were with the Shoguns based in Edo (Tokyo).
Meiji RestorationMeiji made Edo the formal east capital (now named Tokyo) with the recognition of economic power. He abolished feudalism with powers moving out of the Shoguns, Daimyos and Samurais. That said, many believe that oligarchs still had a quite a large power even after the restoration.
The emperor brought a modern army by extending the power to bear arms beyond just the samurai. The disgruntled samurai were then employed in various government bureaucracy. The transition to modern army and navy made Japan stand out in Asia and allowed it to eventually deal with the west on more equal terms.
In parallel, there was a massive industrial revolution. A ministry of industry was created in 1870 and a whole bunch of industrial conglomerates called the Zaibatsu arose. Literacy rose quickly and women were employed in large numbers by the nascent industries. This crashed the birth rates and the newly liberated classes were now openly adopting western culture and clothes after centuries of domination by the samurais.
In the 40 year period from 1872, railways went 400x from 18km to 7100km. Coal production multiplied 30 times. Silk production multiplied 10 times and merchant ships multiplied 60 times.
20th century warsThe massive growth of economy, partially helped by lack of competition in Asia, and a modern army brought a very aggressive Japan at the turn of the 20th century. Its first victim was Russian Empire and the defeat of Russia in 1905 was a major coup. Getting recognition from this, Japan fought with the allies in WW1.
After WW1 it felt cheated that it got none of the colonies from the losing powers and tried to go on its own. With a very hungry domestic economy, it had to go for more and more resources. This led it to occupy Korea, China and eventually most of East Asia. Their aggression and ambition was matched by Nazis on the west and thus they both entered into a marriage of convenience, although neither side really liked the other.
As Japan feared the entry of the US into the war, it tried to preempt by attacking Pearl Harbor in Hawaii. Their gamble failed due to multiple reasons including not attacking Hawaii's oil stores and aircraft carriers. This left US only partially wounded, but very angry. US had its revenge in a war that climaxed with the dropping of atom bombs.
Post-war reconstructionJapan was thoroughly beaten and totally disgusted with war. They put in their constitution to effectively outlaw war and put all their energies in economy. US liked such a distraction as that would mean Japan would not become a major threat and also be its big trading partner in Asia, especially after China fell to the Communists in 1949. Gen. Douglas MacArthur was especially instrumental in this transformation. After the Korean war in 1950s and rise of cold war, Japan became US' principal ally in the Pacific - bringing more aid, more technology and more trade.
While the war left the infrastructure broken, it left a highly educated and motivated populace who could now rebuild the cities with the state of the art 20th century technology instead of saddled with old infrastructure.
Japanese government and its Ministry of International Trade and Industry on its part did a fantastic job pushing their corporations to dominate world trade. With rising education, falling fertility, Japan enjoyed a massive demographic dividend - with parents totally focusing on careers unimpeded by children [or so they thought that time].