You have to guess, based on what is most likely the intended meaning.
Let's try to translate literally as much as possible and I'll try to demonstrate what I mean...
For the two examples that you gave:
日本{にほん}に行{い}ったら日本語{にほんご}を習{なら}う
when go to Japan / will learn Japanese
トマトやりんごを投{な}げた
threw tomatoes and apples
In English, these sentences sound incomplete. But this is exactly the way to speak and write in Japanese.
So how do you make sense of something like this?
when go to Japan / will learn Japanese
Well, it's very likely that this is not the first sentence in a book or magazine article, and it's equally unlikely that it would be the beginning of a conversation. So what came before? Let's imagine... ~Woo0O0oo~~~
【You're in a classroom and the teacher points to you and says:】
マイケル君{くん}、日本{にほん}に行{い}きたいですか?
Michael, do (you) want to go to Japan?
Michael, / want to go to Japan?
はい、行きたいです。
Yes, (I) want to go (to Japan)
yes, / want to go
じゃ、日本に行{い}ったら何{なに}をしますか?
OK. What will (you) do when (you) go to Japan?
OK. / when go to Japan / what will do?
そうですね。。。日本に行ったら。。。日本語{にほんご}を習{なら}います!
Well... When (I) go to Japan... (I) will learn Japanese!
well... / when go to Japan... / will learn Japanese!
Now, if you go back one more time and read just the grey direct-translated bits in a funny Japanese accent, you'll realize that the dialog is perfectly understandable within the context of a classroom conversation between student and teacher.
If you were to go back into the Japanese sentences and put in things like watashi-wa and anata-wa then everyone else in the classroom would be like, "Why do they keep making such a big deal about the fact that they're talking to one another?" It would sound strange and overly dramatic. But to English speakers, we're used to always having those words, and without them it feels strange.
Plus, in English we have to make our verbs and subjects agree to make sense, and if there's no subject specified to begin with, well that's not easy. Japanese doesn't make you do this agreement, so the verbs feel OK by themselves.
Back to your question though, the only thing providing a subject in these kinds of example sentences is whatever fits the most likely circumstances of the utterance. So, you have to get used to guessing at it; and the way most people speak and write, you'll probably guess correctly most of the time.