The earliest records on Japan are from Chinese documents. One of those records said there were many small countries (in Japan) which had wars between them and later a country, ruled by a queen, became the strongest, unified others, and brought peace.
The Japanese began to write their own history after the 5th and 6th centuries, when people from Korea and China taught Japan about the Chinese writing system. Japan's neighbours also taught them Buddhism. The Japanese changed Buddhism in many ways. For example, Japanese Buddhists used ideas such as Zen more than other Buddhists.
In the ancient and Middle Ages, China gave Japan many new cultural ideas, but their friendship became weaker later. In the late 13th century, Mongolians from China tried to invade Japan twice, but they could not.
The samurai and shogun of Medieval Japan are similar to knights and lords in Medieval Europe.
Japan had some contact with the Europeans in the 16th century. The Portuguese were the first Europeans to visit Japan. Later, the Spanish, English and Dutch came to Japan to trade. Also, they brought Christianity. Japan's leaders welcomed them at first, but because Europeans had conquered many places in the world, the Japanese were scared they would conquer Japan too. So the Japanese did not let the Europeans come into Japan anymore, except in a small area in Nagasaki city. Many Christians were killed. Only the Chinese, Korean and Dutch people were allowed to visit Japan, in the end, and they were under careful control of the Japanese government. Japan was opened for visitors again in 1854 by Commodore Matthew Perry, when the Americans wanted to use Japanese ports for American whale boats. Perry brought steamships with guns, which scared the Japanese into making an agreement with him.
This new contact with Europeans and Americans changed the Japanese culture. The Meiji Restoration of 1868 stopped some old ways and added many new ones. The Empire of Japan was created, and it became a very powerful nation and tried to invade the countries next to it. It invaded and annexed Ryukyu Kingdom, Taiwan, and Korea. It had wars with China and Russia: the First Sino-Japanese War, the Boxer Rebellion, the Russo-Japanese War, and the Second Sino-Japanese War, which grew to become a part of World War II when Japan became allies with Nazi Germany and Fascist Italy.
In 1941, Japan attacked Pearl Harbor in Hawaii, a water base of the United States, and destroyed or damaged many ships and airplanes. This started the United States' involvement in World War II. American and Japanese forces fought each other in the Pacific. Once airbases were established within range of the Japanese mainland, America began to win, and started dropping bombs on Japanese cities. America was able to bomb most of the important cities and quickly brought Japan close to defeat. To make Japan surrender, the United States dropped two atomic bombs on the cities of Hiroshima and Nagasaki, killing 150,000 Japanese citizens. Soon after this the Soviet Union began to fight against Japan, and the Japanese army in Manchuria lost. Japan surrendered and gave up all the places it took from other countries, accepting the Potsdam Proclamation. The United States occupied Japan and forced it to write a new constitution, in which it promised to never go to war again.