I'm new to Minecraft and I want to go mining, but I don't want to encounter any monsters. Basically, I'm searching for Iron so I can make buckets, armour and swords. If I lit a whole cave with torches, would they still spawn? Can you explain what goes on in these caves?
Quite simply, yes, monsters will spawn anywhere it is sufficiently dark (light level 8 or less for most hostile mobs). However, if you light an area, it will not spawn monsters.
If you want to play without hostile mobs on, you can turn the difficulty to "Peaceful", but some features of the game will be unavailable since they require items obtained from such mobs.
While that's all you really need to know to play Minecraft, if you're looking for some more specific information, here's a better description of Minecraft mob spawning.
Mobs come in three varieties: hostile, passive, and water. Hostile mobs have a chance of spawning once every game tick, which is a 20th of a second.
Minecraft calculates first whether or not it has room for more mobs. Mobs are capped at a certain number in a 17x17 chunk grid around the player, so if there are too many mobs, Minecraft won't spawn any more. If the check says it's okay to spawn more mobs, Minecraft randomly selects a location to spawn a mob in a 15x15 chunk area.
The location then goes through a series of checks to see if it's suitable for hostile mob spawns. First of all, no mobs will spawn in a 24 block radius spherical zone around the player, unless they're spawning from a mob spawner. Then it checks to make sure that there is enough space for the mob to spawn. After these initial checks, it then checks the light level. This must be 8 or lower for nearly all hostile mobs.
Slimes are the exception to these rules, and they have some quirks in their spawning algorithms. Slimes will only spawn in slime chunks, which are randomly determined based on the world seed. Roughly 10% of all chunks in a world are slime chunks. Slimes do not pay any attention to light level, and can spawn even in direct sunlight. They only spawn under level 40, though, so you won't see them on the overworld too often. Additionally, slimes will only spawn 1/10th of the time compared to other mobs, so they are much less common.
For more information of spawning algorithms, check the Minecraft Wiki page.