Publicly traded companies, like IBM, Google, and Amazon are listed on stock exchanges around the world. People, other companies, mutual funds, and the like are able to buy shares of these companies. When they buy shares, then become stockholders. In other words, they own a part of the company.
With the advent of online brokerage firms (etrade, ameritrade, for example), even the average person can own stocks very easily. For a small fee, they are able to buy and sell these companies.
The goal of stockholders is very clear. They invest in companies to make money, pure and simple. They can make money in two ways. First, some companies pay dividends. This basically means that they give a certain percentage a few times a year to all shareholders. Second, if the stock goes up, as the company is profitable, this produces wealth for shareholders, whose shares go up as well.
With this stated, there are risks as well, as you can imagine. Share could go down.