You can purchase you train ticket either at the train station or online in advance. I advise to buy it in advance as the prices tend to be more expensive closer to your travel date, and you risk that no tickets available anymore.