On time usually refers to if something was scheduled and you got there on schedule, in time is usually used if something wasn't scheduled. For example, on time:
Suppose an employee went to work and his boss told him to be there at 8:00 sharp, then he arrived at 8:00. The boss might say "You're right on time! Be early next time."
suppose there was this person who was drowning and his friend was there, but could do nothing about it because she was tied up to a tree, then another one of their friends came. The girl tied up to the tree might say, "John! You're just in time! Lucy's drowning, save her, then help me out of this tree quickly!"