Can be anything from studying Japanese (language school visa) to "just living" (permanent resident). It's a bit difficult to get a work visa in Japan without a professional qualification, but once you get that it is easy to stay longer. I guess most of the young foreigners are studying or teaching English while working part time, while others are mostly doing real jobs.