Japan was a feudal country until the 1850's when an American navy fleet lead by a man named Perry proved that if Japan didn't modernize, it would easily be crushed by the rest of the world. This broke the 200 year isolation law of sakoku where anyone who tries to leave dies and anyone who tries to enter dies as well. In short, America strong-armed Japan to modernize.
The reason Japan was in a state of sakoku was to preserve its culture and maintain itself as a powerful nation independent from outside help.
After the Meiji Restoration where the military leader of Japan (aka the Shogun) was set down to an adviser and the true Emperor was placed back on the throne, America's treaty that Perry brought over strictly controlled Japan's resources and worldwide influence. The Japanese didn't like this.
After 80 years of rapid modernization, possibly the quickest modernization in history, Japan started conferences without the USA and (after building their own Navy and Military Forces) joined the Axis in World War II.
With the resources still pouring in from the USA and Axis as its allies, Japan started an offensive against Korea, Taiwan, and China. Enslaving the people, murdering all resistance, and destroying their conquered country's cultures and enforcing their own culture, Japan forced Korea, China, and Taiwan to lose their own history and even language during all of World War II.
Seeing Japan's harsh betrayal, America cut off Japan's resources of oil and other materials that couldn't be manufactured in the country. Placing battleships in Pearl Harbor as a "defense" against a Japanese attack, the USA baited a trap for Japan.
Japan took the bait and bombed Pearl Harbor giving the USA an incentive to join the Allies and stop being neutral. This also pulled America out of the Great Depression and mobilized all US citizens to support the war. Lots of propaganda and cartoons against Germany and Japan were made to influence the public before Pearl Harbor was bombed making it seem the USA was preparing for this moment.
Japan's old feudal ways were very strong during this time as well with heartless inhumane experiments being conducted on prisoners including cannibalization. This is why no Japanese prison taken after surrender was left to live.
Meanwhile the USA was in a wild race with Germany and Japan to develop the first nuclear weapon. The USA bombed Tokyo in the guise of a regular attack when in reality it was to destroy Japan's only nuclear reactor producing uranium.
The USA did a similar attack against German forces and eliminated their refining plant. Left with the tools to create bombs but no material, Japan begged Germany for resources. Germany then sent three (or something close to that) U-Boats (aka early submarines) to Japan stocked with pure Uranium.
While on mid-transit to Japan, Germany surrendered and to prevent another economic backlash like World War I, the U-Boats surfaced and were handed over to the US Military.
Japan, without any way to create nuclear arms but determined to fight to the last breath, fought on until the USA threatened to use their newly developed nuclear bomb on them. Thinking it was a bluff but still cautious, Japan mobilized their forces to defend Tokyo against such a bombing while still pressing on against the USA refusing to surrender.
The United States then unleashed their first atomic bomb on Hiroshima. Japan recoiled with the horror at this new weapons raw power. The US told Japan to surrender once again, stating they had another bomb. Japan thought this too was a bluff. The second bomb was sent over Nagasaki further devastating Japan. The USA told Japan, again, to surrender or they will bomb again. Japan, believing the USA would turn their entire nation into a nuclear wasteland, surrendered not knowing the USA only had 2 Atomic Bombs.
If the USA hadn't bombed Japan, Japan would have never surrendered and an both North America and Japan would have taken huge losses. Although not ethical, it was a necessary means to stop a long and bloody conflict.
Today the USA is now Japan's military services. Having forced Japan to adopted a Constitution much like their own, Japan's feudal ways were smashed. The Emperor was reduced to a figurehead and a president was elected. Japan is now not a militarily powerful nation but is the quickest technologically growing nation today. Although American influence has been harsh and brutal, Japan was not reduced to another 3rd world country and still has its closely guarded culture.
In short. I believe Japan being bombed was needed although I'm not happy about it.