Here's how it works: a bee hive / ant colony starts with a winged queen, who digs a nest, sheds her wings (if she's an ant), and begins to lay eggs. They start as workers (all female), whom are kept from becoming reproductive by chemicals the queen produces that stunt the development of other workers.
At her will and once the colony is large enough, she will produce eggs destined to become reproductives: princesses and princes. These are often fed different food and develop for longer.
Royal jelly, for example, is fed to the bee larvae destined to become reproductives. I should also point out that bees and ants can choose the gender of their offspring: unfertilized eggs become male, and queens, which store sperm in special organs in their body, selectively fertilize or not fertilize each egg.
During mating season, the reproductives fly out of the nest and mate in the air. Males die, and the mated females go off to become new queens and start brand new nests.
What happens if an extant queen dies? Sometimes the colony dies with her. At other times, a worker or several workers actually start to lay eggs and one eventually takes over as queen, usually by killing other egg-laying workers. Sometimes rebel workers lay eggs while the old queen is alive, but the latter will eat them before they hatch.
EDIT: Please see Tal Reichert's answer for awesome honeybee specific information.