Most people who have money on the stock market don't really know if they're investing, speculating or gambling - and there is absolutely some overlap between the three. These three activities are, as far as I can see it, three very distinct approaches to making (and losing) money on the stock market.
Gambling involves putting money down and risk losing it. The problem with gambling is that, for most players, it's not actually about winning, it's about playing. Have you ever met a gambler that won money and said he was done gambling now? That his wins were finally good enough and he could withdraw from playing? Probably not.
The same goes for the gambing approach with investors; they might think a small medical company, for example, might strike it big, so they put a lot of money down on a penny stock and either lose it all or gain it back 400-fold if the company discovers the cure for Ebola. It's a gamble, and there is never any way for people to know if it will pay off.
Personally, I find most investment gamblers have a very poor relationship to money. They might lose heavy several gambles in a row, win one and feel it's worth it. The game is what matters, not the balance or the final outcome.
Speculating is doing something despite there being an inherent risk. You don't know if Alibaba is going to go up or down after their IPO, so you buy stock as early as possible, because you feel fairly confident that it's going to go up. You're not sure, but you've got a pretty good idea that's where it's going. You've done your homework and feel like the current value of the stock is lower than what it "should" be and think the market will surely correct this, at which point you can sell for a profit.
I see a lot of day traders as essentially speculators. They look at a stock that's just dipped below where it tends to be during that point of the day, and pump in $10,000 assuming that it's going to rise back to where it was, then sell it off once it reaches that point (or slightly higher), because the assumption is that the next motion will be down again. There's some huge money to be made in speculation, but it's also risky and takes a lot of time and effort.
If I had a massive sum of money, no dayjob and could trade stock without any fees, I would be more inclined to speculate. Right now, though, it just really isn't worth it.
Investing is being aware of the risk and playing what you think the odds are. The time scale is also much longer than in simple speculation. An investor might be familiar with the overall trends of certain markets and individual stocks during long term and finds the odds of that trend continuing to be fairly certain. He/she invests money in several different stock from different markets, knowing that even if one market or company were to have a slump or recession, your other investments would still pay off in the long term. A long-term investor approaches the market with the mind of a technician, not caring as much about the possibility of quick wins, but rather the mind of a person who has a specific end goal.
None of these three is better than the other; I think I should point that out, but they do portray very different personality types. I see myself as an investor, but have a few small gambles; mainly penny stock that might grow a lot very suddenly if the company strikes it big.