Not sure about immigration numbers but after WWII Japan basically has left every other nation alone and don't get involved in other countries' affairs like the US and UK do for example. Minding your own business has positive results.
Japan does not "import" anybody. People are not cars. People either emigrate, migrate or they apply for political asylum. Out of several thousands who have applied for asylum, less than a dozen have been approved.
You may not have heard of the Japanese red Army where during the 1970's some Japanese right wing nutcases did a raid on Tel Aviv airport and took hostages. Some died in the ensuing melee. one of them was on the run for about 25 years, was captured and is now doing a life sentence in a japanese prison.
I don't answer why Japan does not have terrorist attacks because there could be many reasons for that. But on Muslims, Japan is not accepting many of them, just few of them.