How are the Republican and Democratic presidential candidates chosen?

How are the Republican and Democratic presidential candidates chosen?