What Eliot and Elena wrote were totally right.
Hai is quite useful word we often use.
I would add some other cases where we Japanese use "はい(hai)”.
At a class room, if I'd like to show my opinion, I should say "hai" before starting to talk. "Hai" means "I have a opinion."
If someone ask "Where is Sho?" to find me in some crowded place, I would reply "hai." "Hai" means "I'm here." or "I'm Sho."
If I want to ask some one to repeat to say something, I say "hai?" "Hai?" is used like "sorry?", "pardon?" or probably "what?"
Also, we use "Hai" as "ok, then..." or "well..." to break the ice in the conversation.
In addition, here's an interesting example.
If two Hai are combined, as "hai-hai", it gets to have different nuances.
It would mean something like "ok, ok, whatever."
In this case, I put stress on the latter "hai."