I don't think Japan is a particularly racist country. Compared to Koreans, Chinese, Dutch, Belgians, Austrians, Arabs, Indians and lots of others, I would be inclined to say that the average Japanese is less racist.

When it comes to accepting immigrants, we have to consider the different histories of countries: Canada, the US and Australia are nearly entirely made up of immigrants. This affects their policies, and they all accept a lot of immigration. That said, Australia's immigration policies are historically racist: they always discriminated in favour of European immigrants and against immigrants from other parts of the world, including Asia, until recently. The western states of the US had a racist, anti-Asian policy during the 19th century. If they didn't have, California would probably be majority Asian today. Other than that, the US and Canada have accepted immigrants from pretty much anywhere for a long time. In Europe, there has always been substantial migration between countries, and this was rarely controlled until fairly recently (and now, of course, EU citizens can move between EU countries without any restrictions at all). For such countries to set up strict anti-immigration rules goes against the grain of history. If you contrast that with Asia, you find that Japan, China and Korea were all completely closed to foreigners for long periods of time between the 15th and the 19th centuries. For those countries to open themselves up to large-scale immigration equally goes against the grain of history.

My theory is that Westerners think Japanese are racist because they experience discrimination and negative stereotyping for the first time in Japan (though it is quite mild). It doesn't occur to them that in their home countries just as much, or more, discrimination and stereotyping takes place against immigrants daily.

Where migrants go depends on many factors including especially proximity and historical ties. For most, except those from China, Korea and the Philippines and SE Asia, neither history nor geography make Japan an obvious destination.

As to the Japanese stereotyping of migrants (especially those from China) as criminals, it is not wholly unjustified. Compared to the quite low level of crime in Japan, crime committed by migrants is relatively high (unless the statistics are falsified, which is possible).