Japan has done many things over the years to prevent damage to buildings during earthquakes such as implementing strict building codes and retrofitting older structures. Japan has also developed many devices, such as isolation pads, to absorb the shock from earthquakes and dampen the movement one causes.
Building codes in Japan are much more stringent in matters such as how far a building is allowed to sway than in the United States. They have also spent billions of dollars to upgrade existing buildings that are at risk for collapse, fitting them with the most advanced technology. One such piece of technology is called the base isolation pad. These pads are large rubber-and-steel pads that are installed at the bottom of a building where it is first excavated. The building sits on the pad where it absorbs the shock of the building when it moves.
Another piece of technology for preventing earthquake damage in Japan is the energy dissipation unit. These units are installed into a building's structure. Basically, they are giant hydraulic cylinders that elongate and contract as the building sways. Their movement allows them to absorb a great deal of movement when the building shakes. Researchers and structural engineers also continue to monitor past events and building collapses to better understand how to prevent them.