Japan is located just above where tactonics plate meets, this are is most prone to earthquakes.
Now about your question, its not like no building fall when earthquakes come, but eveertime they fall they learn their mistakes, and like in our country most of the building fall due to poor material used in making the buildings, and i should'nt say this, but our country has a very high rate of corruption, so contractors use local material for making buildings and take most of the money by givernment to itself.
but the case in japan in very different, people are very sensible and you would find this very weird but japan has the lowest rate of corruption. so they take oublic safety very seriously, and they build a building with minimum probability of falling ang maximum accuracy.
SEARCH INTERNET ABOUT JAPAN CRIME AND CORRUPTION, YOU WILL BE AMAZED.