Gaijin is simply a Japanese word which means “foreigner” or “outsider,” but it has come to be associated with some complex connotations in Japanese culture. While the word once had a fairly neutral association, it is viewed as impolite in some social groups today, and some people choose to use other words to describe people of foreign extraction. This is particularly true in the Japanese media, where a closely related word, gaikokujin, is typically used instead of gaijin.
Originally, this word was used to refer to strangers or outsiders, but not to people from foreign countries. When the Japanese had contact with people from other countries, they used a variety of terms to describe them before gaijin came to be used in reference to foreigners. Many foreign visitors to Japan were radically different from their hosts, attracting a great deal of attention thanks to their unusual habits and distinctive appearances. For this reason, it is perhaps not describing that a word which means “stranger” came to be used in reference to foreigners, especially Europeans.
The use of a word which originally meant “outsider” to describe foreigners could be construed as an example of Japan's famously insular and sometimes very elitist culture. However, in some parts of Japan, the word actually had positive connotations at various points in history, referencing the often formidable economic power of foreigners doing business in Japan. At other points in history, this word had fairly neutral connotations, being used more like an adjective than an epithet.
However, this word often appears in slang phrases which are denigrating to foreigners, and some people find it offensive as a result. For this reason, gaijin is often replaced with gaikokujin, which literally means “foreign country person,” rather than “outside person” when translated from the Japanese. Foreigners in Japan may sometimes jokingly refer to themselves as gaijin, referencing the struggles they have had while adapting to Japanese society and culture. Although Japan now welcomes foreigners, they are still unusual enough in some regions for calls of gaijin da, or “there goes the foreigner” to ring out when visitors from other countries walk down the street.
Many languages have a special word for describing outsiders, and the usage of such words is often very subtle and difficult for outsiders to understand. Especially in a place like Japan, where people obey a complex and very rigorous social code, it is a good idea to do extensive research before traveling to Japan or interacting with Japanese companies. Otherwise, one may find oneself being called a “stupid gaijin” behind closed doors.