Japan spent a few centuries in isolation, not having a care about the outside world. Then the outside world literally blasted their way into Japan in the 19th century and forced them into the modern age, and Japan realized how *woefully* behind they were and set forth to remedy that.
For the next several decades, Japan, at the Emperor’s direction, sought to modernize. The culture of Japan at the time is what is *really* important, here; the *Emperor* wanted it to be this way, so naturally everybody complied (with the exception of the Satsuma Rebellion, but that’s a relatively minor detail). With the entire population automatically on board with the change in the way society operates, it isn’t much of a surprise that they went from isolated backwater to full-blown military power in a few decades.